Hi everyone, Using the script, I need to get the uptime % of the host. If the uptime drops down to zero, i need to do a fcping and check if i get a positive response. If I get a positive response, it's a Network issue else I need to check the HBA status if it is offline. I'm new to perl scripting, not sure how to proceed. In Other Words, 1. Check the uptime% with SNMP. 2. If SNMP returns a downtime check with fcping if the fabric is up. If fcping returns positive then the SNMP downtime is because of a network issue. If fcping does not work check if the HBA status is offline. Here's the partial code of my script, I'm not sure if it works:
_________________________________________ #! /usr/bin/perl use strict; use Net::SNMP; my $uptimeOID = '1.3.6.1.2.1.1.3.0'; foreach my $host (@ARGV) { my ($session, $error) = Net::SNMP->session( -hostname => $host, -community => 'public', -port => 161 ); warn ("ERROR for $host: $error\n") unless (defined($session)); my $result = $session->get_request( -varbindlist => [$uptimeOID] ); if (!defined($result)) { warn ("ERROR: " . $session->error . "\n"); } else { my $days = $result->{$uptimeOID}; my @TEMP_ARRAY_1 = split(",", $days); $TEMP_ARRAY_1[0] =~ s/days//g; my @TEMP_ARRAY_2 = split(":", $TEMP_ARRAY_1[1]); $days = $TEMP_ARRAY_1[0] + $TEMP_ARRAY_2[0] / 24 + $TEMP_ARRAY +_2[1] / ( 60 * 24 ); print $days; if($days == 0) { my $res = `fcping -d`; my @temp_arr = split(" ", $res); my $port = $temp_arr[2]; chomp($temp = `fcping $port`); @TEMP_1 = split("and", $temp); @TEMP_2 = split(" ", $TEMP_1[1]); if($TEMP_2[0] eq "0") { print "Network Issue"; } else { print "Check HBA Status"; } } } $session->close; } ___________________________________________
fcping output looks like this:
# fcping -d Discovered Port 50:06:0E:80:03:27:AA:11 # fcping 50:06:0E:80:03:27:AA:11 Pinging port 50:06:0E:80:03:27:AA:11, LUN 0 with SCSI Inquiry: Port 50:06:0E:80:03:27:AA:11 replies in 0.013 s as HITACHI OPEN-E + . Port 50:06:0E:80:03:27:AA:11 replies in 0.014 s as HITACHI OPEN-E + . Port 50:06:0E:80:03:27:AA:11 replies in 0.012 s as HITACHI OPEN-E + . 3 successful and 0 unsuccessful pings. Average ping time: 0.013 s. Minimum ping time: 0.012 s. Maximum ping time: 0.014 s.
Can somebody help me with this?

In reply to getuptime script by deepupower123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.