Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

Network Change & Configuration Management

Reply
Highlighted

Raising custom issue with Perl

Techie
Posts: 7
2364     0

Hi,

I can't seem to be able to get NetMRI to register that an issue was raised.  I can generate the issue ID when the script is running but it's not clear on how to make NetMRI pay attention to it.  A little piece of the code is pasted in below.  All the logic works.  In the custom log, I see the two lines I had added to let me know the interface was found and that an issue ID was generated.  I have a feeling there's a step I need to take with the $issue_id I generated below but don't see any examples.  The custom issue exists in NetMRI and I can trigger it with a CCS script so I must be missing one little piece with Perl.

 

for $interface (@l2interfaces) {
    if ($rstp_enabled eq "yes") {
      if (! defined ($rstp_enabled{$interface})) {
      $misconfigured_rstp{$interface} = "misconfigured";
      #$easy->send_command("DEBUG: rstp $interface busted");
      $easy->log_message("warning", "warning message $interface");
      $issue_id=$easy->generate_issue("l2portnoxstp", "warning", { "host" => "$ipaddress", "name" => "$name",});
      $easy->log_message("info", "issue ID is $issue_id\n");
      }
    }
}

 

---  Custom log entries ----

2017-05-30 15:29:31 [WARNING] warning message ge-1/0/44

2017-05-30 15:29:32 [INFO ] issue ID is 544828

Highlighted

Re: Raising custom issue with Perl

Adviser
Posts: 422
2364     0

Here is an example Smiley Happy

 

my $easy = NetMRI_Easy->new;
our $device_id;
our $ipaddress;
our $name;
our $batch_id;

	$easy->broker->issue_adhoc->generate_issue(  
                DeviceID => $device_id,
                IssueTypeID => "HPportAAAcfg",
                Severity => "Error",
                BatchID => "$batch_id",
                DeviceIPAddress => $ipaddress,
                Name => $name,
                Port => "Num");
	$easy->log_message("info", "raised issue");
	$easy->log_message("info", "job = $batch_id");

Let me know if that worked, let me know the version you are using and I can test it.

 

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh
Highlighted

Re: Raising custom issue with Perl

Techie
Posts: 7
2364     0

Hi,

So my version of the script started working after the license was updated.  The old license didn't expire so restarting things must have done the trick.  We are running version 7.1.3.86453.  The issues tab on the job viewer now says the issue was raised and it shows up on the Network Analysis -->  issues tab.  I will try your version with issue_adhoc rather than generate_issue.  

 

Here's the full script in case something jumps out at you.  The script gathers some output and then tries to determine if all of the L2 ports are assigned to a rapid spanning-tree instance and if vstp is configured, check there too.  The first part just creates an array of L2 interfaces.  Then a hash is created based on the configuration using the interface names as the key and just a little flag as the value.  Then all of the interfaces that are running in switchport mode are checked against the hash and if nothing is returned, we know we are missing an interface in the config.  

 

# BEGIN-SCRIPT-BLOCK
#
# Script-Filter:
# $sysDescr like /junos/i
#
# END-SCRIPT-BLOCK

#use strict;
use warnings;
use NetMRI_Easy;

$easy = new NetMRI_Easy({ api_version => 'auto' });

$rstp_enabled = "no";
$vstp_enabled = "no";
$xstp_broken = "no";

$xstp_config = $easy->send_command("show configuration protocols | display set");
$rstp_config = $easy->send_command("show configuration protocols rstp | display set");
$vstp_config = $easy->send_command("show configuration protocols vstp | display set");
$ethswitch = $easy->send_command("show interfaces terse | match eth-switch");
@xstp_config = split ("\n",$xstp_config);
@rstp_config = split ("\n",$rstp_config);
@vstp_config = split ("\n",$vstp_config);
@ethswitch = split ("\n",$ethswitch);

for (@xstp_config) {
if ($_ =~ /rstp/) {
$rstp_enabled = "yes";
}
if ($_ =~ /vstp/) {
$vstp_enabled = "yes";
}
}

# extract interface from line "ge-1/0/4.0 up up eth-switch"
for (@ethswitch) {
if ($_ =~ /(ge-\d+\/\d+\/\d+|xe-\d+\/\d+\/\d+|et-\d+\/\d+\/\d+|xle-\d+\/\d+\/\d+|ae[0..32])/) {
push (@l2interfaces,$1);
}
}

for (@rstp_config) {
if ($_ =~ /(ge-\d+\/\d+\/\d+|xe-\d+\/\d+\/\d+|et-\d+\/\d+\/\d+|xle-\d+\/\d+\/\d+|ae[0..32])/) {
$rstp_enabled{"$1"} = "yes";
}
}

for (@vstp_config) {
if ($_ =~ /(ge-\d+\/\d+\/\d+|xe-\d+\/\d+\/\d+|et-\d+\/\d+\/\d+|xle-\d+\/\d+\/\d+|ae[0..32])/) {
$vstp_enabled{"$1"} = "yes";
}
}
# Check done if only rstp enabled on switch

for $interface (@l2interfaces) {
if ($rstp_enabled eq "yes") {
if (! defined ($rstp_enabled{$interface})) {
$misconfigured_rstp{$interface} = "misconfigured";
$rstp_broken = "yes";
#$easy->send_command("DEBUG: rstp $interface busted");
$easy->log_message("warning", "warning message $interface");
$issue_id=$easy->generate_issue("l2portnoxstp", "warning", { "host" => "$ipaddress", "name" => "$name",});
$easy->log_message("info", "issue ID is $issue_id\n");
}
}
if ($vstp_enabled eq "yes") {
if (! defined ($vstp_enabled{$interface})) {
$misconfigured_vstp{$interface} = "misconfigured";
$vstp_broken = "yes";
$easy->send_command("DEBUG: vstp $interface busted");
}
}
}

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You