Reply

Problem with the method: get_custom_field

SChacon
Techie
Posts: 5
2304     0

I try to do a Perl script to check if a custom field for a device have a value. I try to use the method get_custom_field($field_name) but I don't understand how it's works. I put my script. Can you help me?

______________________________________________________________________________

use strict;
use warnings;
 
# script variables are provided as a global variable from the NetMRI job engine.
our $command;
our $output;
 
# NetMRI_Easy is a library that provides an easy interface to the NetMRI. You open a connection to the NetMRI by creating an instance of NetMRI_Easy. In this example, we call this instance $easy.
use NetMRI_Easy;
 
# Connect to the NetMRI
my $easy = new NetMRI_Easy;
 
# get the device id from the job engine.
my $device_id = $easy->device_id;
 
# retrieve the device
my $device = $easy->device;
 
my $commandStr;
my $StateJob;
 
$easy->log_message('info', $device->DeviceID . " " . $device->DeviceName);
$commandStr = "ping " . "10.1.1.100";
$StateJob = $device->get_custom_field(custom_state);
$easy->log_message('info', $device->get_custom_field(custom_state));
$output = $easy->send_command($commandStr);
if ($output =~ /Success rate is 100/) {
if($StateJob =~ /2/){
$StateJob = "0";
$easy->log_message("custom", "Etape1");
exit 1;
}
else{
$StateJob = "0";
$easy->log_message("custom", "Etape2");
}
}
elsif($output =~ /Success rate is 80/){
if($StateJob =~ /2/){
$StateJob = "0";
$easy->log_message("custom", "Etape3");
        exit 1;
}
else{
$StateJob = "0";
$easy->log_message("custom", "Etape4");
}
}
else {
if($StateJob =~ /0/){
$StateJob = "1";
$easy->log_message("custom", "Etape5");
}
elsif($StateJob =~ /1/){
$StateJob = "2";
$easy->log_message("custom", "Etape6");
        exit 1;
}
else{
$StateJob = "2";
$easy->log_message("custom", "Etape7");
}
}
 
  
  $easy->broker->device->update({
    DeviceID         => $device->DeviceID,
    custom_state      => $StateJob,
  });
Highlighted

Re: Problem with the method:

Adviser
Posts: 418
2304     0

Can you please add the all.zip so we can see where it's failing?

 

Thanks,

Sif

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

Re: Problem with the method:

Adviser
Posts: 418
2305     0

Didn't look though the entire script yet, here is something :

 

$easy->log_message("custom", "Etape4");
should be
$easy->log_message('info', , "Etape4");
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Re: Problem with the method:

SChacon
Techie
Posts: 5
2305     0

Hello Sif,

I have try to change the log_message. The problem is to take the value in the Custom Field. My custom field is State.

I put the all.zip in my dropbox. You can take it.

https://www.dropbox.com/s/totdmt1m09nxc16/all.zip

Thanks for help me

Re: Problem with the method:

Adviser
Posts: 418
2305     0

Add this after all your log statements

$easy->device->set_custom_field(custom_state      => $StateJob);

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh
Showing results for 
Search instead for 
Do you mean 

Recommended for You