New Ranks & Badges For The Community!
Notice something different? The ranks and associated badges have gone "Star Fleet". See what they all mean HERE
Highlighted
Commodore Commodore
Commodore
1971 views

Password parameter in policy template

Jump to solution

Hi Experts

we want to use a policy template password parameter however i'm unsure how to decrypt it when it gets passed to the scriptc called in the policy template.

Can anyone assist?

cheers

Mick

Labels (1)
Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted

Hi

I asked the HP support but unfortunantly they don't tell me anything useful. I examine the agents perl libraries and found the solution. The key is to use the OvParam package. The password parameter which get this way is decrypted.

use OvParam;

my $pwd_param_name = "password parameter name";

# it should be type you can see by ovpolicy -list on the host where policy has been deployed 
my $policy_template_type = "monitortmpl";

my $TemplateObj = new OvParam::Template();
die "Can't create object of OvParam::Template; $!\n"
unless $TemplateObj;
	
if (defined $TemplateObj)	{
	$TemplateObj->Load($Policy->Name(), "monitortmpl");
	my $pwd_parameter = $TemplateObj->GetSimpleParameter($pwd_param_name);
	if(defined $pwd_parameter) {
		$pwd_decrypted = $pwd_parameter->GetValue();
  		print "$pwd_decrypted\n";
	}
		undef $TemplateObj;
} else {
	die "Policy template not defined, can't decrypt password parameter\n";
}

It works for me, Hope it helps.

Aleksandr.

View solution in original post

5 Replies
Highlighted
Admiral Admiral
Admiral

Edit your policy and create a new parameter, supply display name (example password) and parameter name. select the parameter type "string(password)" and enter the password values.

from the policy you can now use the %%password%% as a parameter to your script.

hello_world.sh -p %%password%%

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution. Don't forget to Kudo!!
0 Likes
Highlighted
Commodore Commodore
Commodore

Hi

I figured that much...

the problem is that when the password gets passed to the external script, it is encoded with some random value. in the script, how can i decode the password? i'm assuming there is some function in the agent that might let me do this?

0 Likes
Highlighted

Hi

I asked the HP support but unfortunantly they don't tell me anything useful. I examine the agents perl libraries and found the solution. The key is to use the OvParam package. The password parameter which get this way is decrypted.

use OvParam;

my $pwd_param_name = "password parameter name";

# it should be type you can see by ovpolicy -list on the host where policy has been deployed 
my $policy_template_type = "monitortmpl";

my $TemplateObj = new OvParam::Template();
die "Can't create object of OvParam::Template; $!\n"
unless $TemplateObj;
	
if (defined $TemplateObj)	{
	$TemplateObj->Load($Policy->Name(), "monitortmpl");
	my $pwd_parameter = $TemplateObj->GetSimpleParameter($pwd_param_name);
	if(defined $pwd_parameter) {
		$pwd_decrypted = $pwd_parameter->GetValue();
  		print "$pwd_decrypted\n";
	}
		undef $TemplateObj;
} else {
	die "Policy template not defined, can't decrypt password parameter\n";
}

It works for me, Hope it helps.

Aleksandr.

View solution in original post

Highlighted
Commodore Commodore
Commodore

Hi Aleksandr

 

Thanks very much for the tip, yes support are not useful for these types of questions...

Thanks!

0 Likes
Highlighted

Just another example of OvParam functions for instance and non-instance parameters.

#!/usr/bin/perl

use strict;
use OvParam;

# policy name
my $PolName = 'policy_name';
# policy type
my $PolType = 'monitortmpl';

my $TemplateObj = new OvParam::Template();
	die "Can't create object of OvParam::Template; $!\n"
	unless $TemplateObj;
	
if (defined $TemplateObj) {

	# load policy template
	$TemplateObj->Load($PolName, $PolType);

	# try to load instance names
	my @InstNames = $TemplateObj->GetInstanceParameterNames();

	if(@InstNames > 0) {

		#it's policy with instance parameters, get the instance parameter
		my $InstParam = $TemplateObj->GetInstanceParameter($InstNames[0]);
		if (defined $InstParam) {
		
			# get instance parameters as array of simple parameters
			my @InstValues = $InstParam->GetInstanceValues();

			print "Policy [$PolName] has ".($#InstValues+1)." parameters instance(s):\n";

			for(my $i=0; $i<= $#InstValues; $i++) {
				
				print "Instance parameter [".$InstParam->GetName()."] => [".$InstValues[$i]."]\n";
				
				# get simple parameters names of current instance
				my @sParNames = $InstParam->GetSimpleParameterNames($InstValues[$i]);

				foreach my $name (@sParNames) {
					my $SimpleParam = $InstParam->GetSimpleParameter($InstValues[$i], $name);
					if(defined $SimpleParam) {
						print "  [".$SimpleParam->GetName()."] => [".$SimpleParam->GetValue()."]\n";
					}

				}
			}
		}

	} else {

		my @sParNames = $TemplateObj->GetSimpleParameterNames();

		print "Policy [$PolName] has ".($#sParNames+1)." simple parameters:\n";

		foreach my $name (@sParNames) {
			my $SimpleParam = $TemplateObj->GetSimpleParameter($name);
			if(defined $SimpleParam) {
				print "  [".$SimpleParam->GetName()."] => [".$SimpleParam->GetValue()."]\n";
			}
		} 

	}
}
	
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.