The Perl script, as shipped with Network Protocol Manager, is shown in Figure 19 on page 58. You use the sm_edit utility to edit this script to uncomment the appropriate lines and to add the CLI commands, parsing rules, and processing rules that perform the actual processing. You can also add additional initialization prose.

####################################################################
# Network Protocol Manager (NPM) Custom Perl CLI Discovery Probe
# Copyright 2008 by VMware Corporation (“VMware”). All Rights Reserved.
####################################################################
use strict;
use warnings;
use Carp;
####################################################################
# InCharge::Probe Example
####################################################################
use InCharge::Probe;
eval {
 my $probe = InCharge::Probe->new;
 my $session = $probe->{session};
 my $params = $probe->{ga_params};
 my $serverName = $session->getServerName();
 my $elementName = $params->{“elementName”};
 my $elementType = $params->{“elementType”};
        my $snmpName = $elementName;
        if ($snmpName !~ /^SNMPAgent/) {
           $snmpName = “SNMPAgent-”.$elementName;
        }
 my $agentObj = $session->object(“SNMPAgent”, $snmpName);
 my $systemName = $agentObj->getSystem();
 my $sysObj = $session->object($systemName);
 my $sysName = $sysObj->{“Name”};
 my $deviceIP = $agentObj->{“AgentAddress”};
 my $ERROR = “”;
        if ($ERROR) {
                $probe->stop(“$ERROR”);
        } else {
                $probe->setProbeResult(“SUCCESS”);
                $probe->setChanged(“TRUE”);
                $probe->setDiscoveryError(“”);
                $probe->setElementObjectName($elementName);
                $probe->stop();
        }
        $session->detach();
};
if ($@) { croak $@; }
####################################################################
####################################################################
# SMARTS::CLI::Discovery Example
####################################################################
# use SMARTS::CLI::Discovery;
#
# eval {
# $SHELL->cmd(‘terminal length 0’);
# my @results = $SHELL->cmd(‘who’);
# foreach my $result (@results) {
#  # do something with $result
# }
#
# my @interfaces = $SYSTEM->getInterfaces();
#  foreach my $interface (@interfaces) {
#        $interfaceObject = $SESSION->object($interface);
#  # do something with $interfaceObject
# }
# };
#------------------------------------------------------------------
# If $@, the probe fails and the element is put on the pending list.
#------------------------------------------------------------------
# $ERROR = $@;
####################################################################