NA - I need to poll a specific SNMP oid and store the result in a diagnostic.

via the CLI of NA, I can easily run an SNMP GET against the SNMP contact oid. an example of the syntax used is below:
snmp get -deviceid $tc_device_id$ -oid 1.3.6.1.2.1.1.4.0 -timeout 4 -readwrite false

How can I run this as a diagnostic and store the result in the diagnostics so that I can search against it in policies?

Thanks in Advance,

Shannon

  • 0  

    Hi,

    This is doable, but unsure if there's a way to do this as a basic diagnostic. This might be all you were looking to see - can it be a basic diagnostic.....

    Thik you'd need to do this as an advanced diagnostic and then you could use the API command.

    Within the diagnostic script, you could use Client and then issue your SNMP get.  

    You might want to clean up the result data but your diagnostic would have the result.  

    The policy would be just like any policy rule that works with a diagnostic.  

    You'd set up your policy, define the scope and then for the rule, you'd give it a name and specify diagnostic for rule type.

    You define the device family, you can define a text block (or not).

    For condition, select your diagnostic and then you can add more conditions as you need.  

    If you need help with setting up the advanced script or Perl NA API, you can find some info in the documentation, or just reply back.  

    Hope this helps,

    Chris

  • 0 in reply to   

    "If you need help with setting up the advanced script or Perl NA API, you can find some info in the documentation, or just reply back. "

    I have definitely been struggling with the documentation and finding advanced scripting examples that do anything like what I am trying for.

    If you have any link to the documentation that explains what the "device" language for diagnostics, or an example of a script that runs commands in the NA CLI and captures the result, that would be invaluable.

    Thank you Chris!


  • Verified Answer

    +1   in reply to 

    Hi, I resemble that remark and can definitely relate....

    You can skip to the bottom, think the script there should run based on what you've said.  

    Or, you can go through the steps and this might help with understanding NA Advanced scripts.  


    The "easy" answer for advanced diagnostics - the language could be Expect or Perl (OOB options).  That said, you "can" use something else like Python, but there's a bit of extra work.  

    Sort of step #1 - do you know if the Perl API was installed?  If you don't know / not sure, no worries, we'll see once you try to run the script, but this is something you may need to do (no worries, kind of easy, only challenge may be getting any missing Perl modules)

    So, here's what I did back in the day, and it still works and still recommend it....

    Unsure if you're familiar with NA sessions or not, so I'll do a bit of background (you can skip).

    If you are in NA, looking at a device, you can (unless you have it disabled or otherwise blocked) telnet / ssh to a device from the Connect menu

    That'll connect to the NA Proxy, then from there, you'll connect to a device and can issue a command.  

    What I do is I'll pick a device that is similar to what I want my diagnostic to work with (for example, IOS).

    In NA, in the IP or Hostname, I'll enter in this sample device's IP - this will get me to the device home page

    From there, I'll click Connect / Via Proxy using ssh -> from here, like I said above, I get to the Proxy, then in the device.

    I enter something like show users and then I exit out of the device and then out of the proxy and get back to the NA Web UI / device page

    If you then go to View / Telnet / SSH Sessions, you should see your device session that you just did.  

    If you look at this line, you'll see Actions at the end, click on "View Full Telnet/SSH Session"

    That will bring up screen showing what you had entered, nothing that exciting....however, if you look in the upper right corner, you'll see three links, we want to focus on the right two - Convert to Expect Script and Convert to Perl Script.

    I typically go with Convert to Perl Script, so I'm going to say click on that link....

    OK, you now have what looks like a New Change Plan and are thinking, "Chris, I want a Diagnostic, not a Change Plan" - no worries, just hang in there a little longer.....

    The important thing is, this is the start of your diagnostic script.  You have the "wrapper" if you will for everything you need to get a Perl script to run.  

    What I'd suggest is two things:

    1) Take a screen shot of this New Change Plan page

    2) Copy the script lines and stick that in Notepad or whatever you have handy - you'll need this shortly.  

    You can back out of this page.

    Now create a New Diagnostic
    Give it a Name
    Check the box for Advanced Scripting
    Pick Perl
    For Device Family, select the best option (you may be fine with Any Device Family but I try to be more specific)

    Now, enter in the script you copied....

    There are a few changes you'll need to do as there are changes.

    Connect changes to Client
    You're not sending commands at the device
    You'll add in the snmp get command
    One other thing - make sure the device id does not have a "#" in front of it....

    -----------------------------------

    I took an old script I had and modified it to run, so it will be a bit different than what NA may have provided above, but you should easily be able to take the two and merge (if you want) or just use what is below.  Either way, you'll have basics of an advanced script.  

    -----------------------------------

    #!/usr/bin/perl

    use strict;
    use warnings;
    use Getopt::Long;
    use Opsware::NAS::Client;

    my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$');
    my $device = '$tc_device_id$';
    my @output;

    my $nas = Opsware::NAS::Client->new();
    my $res = $nas->login( -user => $user, -pass => $pass, -host => $host, -nosession => '0' );

    $res = $nas->snmp_get( deviceid => $device, oid => '1.3.6.1.2.1.1.4.0'  );
    print $res->result(), "\n";

    $nas->logout();
    undef $res;
    exit(0);

    -------------------------------

    Lastly, the big question now is, "Will it run?"  Give it a try, see what you get back.  

    If you do not have the Perl API installed, then you'll get an error and need to take care of that.  Again, not too bad, but chasing down missing modules can be a pain.  Also, if you are multi-core, make sure this is done on each core.  

    You can find it in the documentation:

    Install Modules of Perl Module

    To run the install script, enter: perl client/perl_api/har/install.pl command.

    Hopefully this helps, if you have more questions, just post back. 

    Good luck,

    Chris

  • 0 in reply to   

    Chris ,


    This worked perfectly on the first pass and after an hour on the line with support I was close, but not quite there.

    I can't possibly thank you enough, but I'll try as much as I can.

  • 0   in reply to 

    Glad it worked for you and hopefully it’ll be the start of many scripts in the future.  

    The first can be the most difficult one, so you’ve passed that test.  Hopefully the code makes sense, if there are questions, just ask.  

    Just a tip, might want to document the script (I know, I should have).  

    Good luck with the diagnostic and policy!  

    -Chris