OS Command Adapter - Single Column
Executes the specified OS command and returns the command output as a single value. The metric result is a 1 row, 1 column table.
Basic Properties
The complete command line will be constructed as: Command + Script + Arguments.
-
Command - The command to execute. For example,
%perlBin%/perl
. The complete command line will be constructed as: Command + Script + Arguments. -
Script - A script to pass to the command. For example,
%scriptsDir%/myscript.pl
. You can upload custom files to the agent, which will be accessible under the%scriptsDir%
directory. -
Arguments - Additional arguments to be appended to the Command.
Advance Properties
-
Input Properties - Additional properties can be passed to the command through its standard input stream. This is usually used for secure content, such as username or passwords, that you don't want to be visible to other users. For example, you can add the following Input Property:
Name=targetName
,Value=%NAME%
which the command can read through it's standard input stream as "STDINtargetName=<target name>".
-
Environment Variables - Additional properties can be accessible to the command from environment variables. For example, you can add Environment Variable: Name=targetType, Value="%TYPE%", and the command can access the target type from environment variable "ENVtargetType".
Note:
Value="%TYPE%" may not be applicable for certain target-types (for example: host, wls). For such target types, use Value=TYPE instead.
Credentials
-
Host Credentials - The credential used to launch the OS Command.
-
Input Credentials - Additional credentials passed to the OS Command's standard input stream.
Example 1
Read the contents of a log file, and dump out all lines containing references to the target.
-
Approach 1 - Use the grep command, and specify the target name using %NAME% parameter.
Command = /bin/grep %NAME% mytrace.log
-
Approach 2 - Run a perl script
Command = %perlBin%/perl
Script = %scriptsDir%/filterLog.pl
Input Properties:
targetName = %NAME%
targetType = %TYPE%
filterLog.pl:
require "emd_common.pl"; my %stdinVars = get_stdinvars(); my $targetName = $stdinVars{"targetName"}; my $targetType = $stdinVars{"targetType"}; open (MYTRACE, mytrace.log); foreach $line (<MYTRACE >) { # Do line-by-line processing } close (MYTRACE);
Example 2
Connect to a database instance from a PERL script and query the HR.JOBS sample schema table.
-
Approach 1 - Pass credentials from target type properties into using Input Properties:
Command = %perlBin%/perl
Script = %scriptsDir%/connectDB.pl
Input Properties:
EM_DB_USERNAME = %Username%
EM_DB_PASSWORD = %Password%
EM_DB_MACHINE = %MachineName%
EM_DB_PORT = %Port%
EM_DB_SID = %SID%
connectDB.pl
use DBI; require "emd_common.pl"; my %stdinVars = get_stdinvars(); my $dbUsername = $stdinVars{"EM_DB_USERNAME"}; my $dbPassword = $stdinVars{"EM_DB_PASSWORD"}; my $dbMachine = $stdinVars{"EM_DB_MACHINE"}; my $dbPort = $stdinVars{"EM_DB_PORT"}; my $dbSID = $stdinVars{"EM_DB_SID"}; my $dbAddress = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$dbMachine)(Port=$dbPort))(CONNECT_DATA=(SID=$dbSID)))"; # Establish Target DB Connection my $db = DBI->connect('dbi:Oracle:', "$dbUsername@".$dbAddress, "$dbPassword", {PrintError => 0, RaiseError => 0, AutoCommit => 0}) or die (filterOraError("em_error=Could not connect to $dbUsername/$dbAddress: $DBI::errstr\n", $DBI::err)); my $query = "SELECT JOB_TITLE, MIN_SALARY FROM HR.JOBS"; my $st = $db->prepare($query); $st->execute(); while ( my ($job_title, $min_sal) = $st->fetchrow_array() ) { print "$job_title|$min_sal\n"; } $db->disconnect or warn "disconnect $DBI::errstr\n"; exit 0;
-
Approach 2 - Pass monitoring credential set using Input Credentials
Command = %perlBin%/perl
Script = %scriptsDir%/connectDB.pl
Input Credentials:
dbCreds = MyCustomDBCreds
connectDB.pl
use DBI; require "emd_common.pl"; my %stdinVars = get_stdinvars(); my $credType = getCredType("dbCred", \%stdinVars); my %credProps = getCredProps("dbCreds", \%stdinVars); my $dbUsername = $credProps{"DBUserName"}; my $dbPassword = $credProps{"DBPassword"};
Example 3
Overriding default monitoring credentials by creating and using a custom monitoring credential set for host target.
Creating host credentials for the host target type:
> emcli create_credential_set -set_name=myCustomCreds -target_type=host -auth_target_type=host -supported_cred_types=HostCreds -monitoring -description='My Custom Credentials'
When you go to the Credentials page of the Metric Extension wizard, and choose to "Specify Credential Set" for Host Credentials, you will see "My Custom Credentials" show up as an option in the drop down list.
Note that this step only creates the Monitoring Credential Set for the host target type, and you need to set the credentials on each target you plan on deploying this metric extension to. You can set credentials from Enterprise Manager by going to Setup, then Security, then Monitoring Credentials. Alternatively, this can be done from the command line.
> emcli set_monitoring_credential -target_name=target1 -target_type=host -set_name=myCustomCreds -cred_type=HostCreds -auth_target_type=host -attributes='HostUserName:myusername;HostPassword:mypwd'