Reply

Custom Fields in a CSS script

community Employee
Employee
Posts: 73
3351     0

Dear All,

I'm looking to understand if it is possible to read a Device Custom Field in a CSS Script.

If yes... How to do so ?

Additionally I wanted to know if we can update this Device Custom Field through a CSS Script.

Sincerely.

Tobias Kull

Re: Custom Fields in a CSS

Adviser
Posts: 414
3351     0

Never tried to use it in any scripts. It would be something like custom_<fieldname>

Make sure it's all lower case and you use "_" where spaces are.

 

You can only update using the PERL API call.

 

Sif

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

Re: Custom Fields in a CSS

user42
Techie
Posts: 35
3351     0

Dear Sif,

Unfortunately I wasn't able to use my Device Custom Field called toping.

I tried Custom_toping and custom_toping and customtoping but the webgui doesn't accept this variable.

BTW : if we could not update a Device Custom Field by CSS and only with a Perl Script do you know if this script could be executed from a NetMRIappliance ?

Sincerely,

Tobias

Re: Custom Fields in a CSS

Adviser
Posts: 414
3351     0

Yes, you could write a NetMRI EASY script that will run in the GUI.

You could also write a PERL script in the Sandbox located in NetMRI

 

What are you trying to accomplish?

Sif

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

Re: Custom Fields in a CSS

user42
Techie
Posts: 35
3351     0

Hi Sif,

It's pretty simple in fact.

We need to check if some equipment is alive in the network.

To do so we created a CSS script which connect each devices from a group and do a ping in NetMRI direction.

If the ping is a success we wanted to update a Custom Device Field called ToPing (yes or no depending on the success).

Unfortunately I encountered two issues, I'm not able to :

1. Do a Script-Filter: based on a Custom Device Field

2. Do update a Custom Device Field

Where could I find more information regarding Perl Script running in NetMRI sand box ?

Below my script if you are interested:

Script:
    Pinger.ccs

Script-Description:
    This script generates an series of issues based on a ping test
    80% or great is a success
    Less than 80% is a failure

Script-Filter:
    $Vendor eq "Cisco"
    and $sysDescr like /IOS/

#########################################################################
Action:
    Ping Host1

Action-Description:
    Execute a ping

Action-Commands:
    ping 172.23.18.9

# modify the IP Address for the ping command

# Example output from a ping command
#
# Type escape sequence to abort.
# Sending 5, 100-byte ICMP Echos to 172.23.18.9, timeout is 2 seconds:
# !!!!!
# Success rate is 100 percent (5/5), round-trip min/avg/max = 48/155/336 ms

Output-Triggers:
    Process PINGGOOD
    Process PINGBAD

#########################################################################
#
# Additional Ping Action sections can be created duplicating the ping test
#
#########################################################################

Action:
    Ping Host2

Action-Description:
    Execute a ping

Action-Commands:
    ping 172.23.18.90

Output-Triggers:
    Process PINGGOOD
    Process PINGBAD

#########################################################################
Issue:
    Process PINGGOOD

Issue-ID:
    PingGood

Issue-Severity:
    Info

Issue-Description:
    Generate info issue that ping was a success.

Issue-Variables:
    $iphost    Ipaddress
    $success    Integer    number

Issue-Template:
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to [[$iphost]], timeout is 2 seconds:
    ...
    Success rate is [[$success]] percent.*

Issue-Filter:
    $success >= 80

Issue-Details:
    FromHost    $IPAddress
    Name        $Name
    ToHost    $iphost
    SuccessRate    $success

#########################################################################
Issue:
    Process PINGBAD

Issue-ID:
    PingBad

Issue-Severity:
    Error

Issue-Description:
    Generate info issue that ping was a failure.

Issue-Variables:
    $iphost2    Ipaddress
    $success2    Integer    number

Issue-Template:
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to [[$iphost2]], timeout is 2 seconds:
    ...
    Success rate is [[$success2]] percent.*

Issue-Filter:
    $success2 < 80

Issue-Details:
    FromHost    $IPAddress
    Name        $Name
    ToHost    $iphost2
    SuccessRate    $success2

#########################################################################

 

CCS cannot update DB variables

BAndersen Employee
Employee
Posts: 15
3351     0

Hello,

  I tried your script and CCS does not appear to be able to update DB fields as the set operator "=" is not allowed only the comparison operator "==" is.  I really like where you are going with this and the options this opens up for enhancing CCS.  I've submitted a feature request and we will see if it is accepted.  Until then, a Perl script is going to be your only option.

  Also, CCS variable are case in-sensitive so $IPAddress = $ipaddress = $ipAddress.

Good luck,
Brad

Sample perl script (untested)

BAndersen Employee
Employee
Posts: 15
3351     0

Hello,
 Here is a script based off some of Sif's excellent work that should point you in the right direction.  This is untested and is just an example to give you some ideas.
Good luck,
Brad

# BEGIN-SCRIPT-BLOCK
#
# Script-Filter:
#     true
#
# END-SCRIPT-BLOCK

use strict;
use warnings;

use NetMRI_Easy;

my $pingoutput;
my $pingrate;
# 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;
#
# Create the custom Device field called pingrate if it does not already exist
#
$easy->broker->custom_fields->create_field({
  model => 'Device',
  name  => 'pingrate',
  type  => 'string',
});

# Example output from a ping command

#
# Type escape sequence to abort.
# Sending 5, 100-byte ICMP Echos to 172.23.18.9, timeout is 2 seconds:
# !!!!!
# Success rate is 100 percent (5/5), round-trip min/avg/max = 48/155/336 ms

$pingoutput =  $easy->send_command("ping 172.23.18.9");

#Log if needed
#$easy->log_message('info', "$pingoutput");

 if ($pingoutput =~ m/success rate is (\d+) percent .* = ([\d\/]+ ms/sgi) {$pingrate = "$1-$2";} #looks like "pingrate - min/avg/max"

#Log if needed
# $easy->log_message('info', "updated pingrate
 = $pingrate");

$easy->device->set_custom_field(pingrate => $pingrate);

exit(1);

Highlighted

Great work Brad here is how

Adviser
Posts: 414
3351     0

Great work Brad here is how to generate an issue

    $easy->broker->issue_adhoc->generate_issue(  
                DeviceID => $device_id,
                IssueTypeID => "MyIssue",
                Severity => "Error",
                BatchID => 0,
                DeviceIPAddress => $ipaddress,
                Name => $name,
                Port => $pingrate);

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