Link to home
Start Free TrialLog in
Avatar of sjb79
sjb79Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Formatting snmp_check sysUpTime output

Hi EE peeps,

I've got a 3Com switch and I'm setting up Nagios to monitor it.  I'm in the early stages of this and have got Nagios pulling the up time off the switch.  So far I've done/got the following;
 
rs3@RS3:/usr/lib/nagios/plugins$ sudo ./check_snmp -H 192.168.0.252 -C public -o sysUpTime.0
SNMP OK - Timeticks: (338739470) 39 days, 4:56:34.70 |
rs3@RS3:/usr/lib/nagios/plugins$

Open in new window


Is there a way of just getting the days value of out this result so I can then set warning and critical levels?
Avatar of Steve Jennings
Steve Jennings

awk { print $6 }
Avatar of sjb79

ASKER

So the command would look like the following;
 
check_snmp -H 192.168.0.252 -C public -o sysUpTime.0 awk { print $6 }

Open in new window

Is that correct?
Sorry, hit submit too quickly.

You need to play with "awk", it will do what you want. For example, lets say you output your SNMP return into a file called "xx" so the contents of "xx" are:

SNMP OK - Timeticks: (338739470) 39 days, 4:56:34.70

Then you could enter:

cat xx | awk -F' ' '{print $6}'

and "39" would be returned because "39" is the 6th column separated by spaces.

So you need to pipe your output into awk to get the "days" number.

Good luck,
Steve
check_snmp -H 192.168.0.252 -C public -o sysUpTime.0 | awk F` ` `{ print $6 }`

You need a "pipe" after the check_snmp command

Test it . . .

Steve
Avatar of sjb79

ASKER

Tried and got this;

rs3@RS3:/usr/lib/nagios/plugins$ ./check_snmp -H 192.168.0.252 -C public -o sysUpTime.0
SNMP OK - Timeticks: (348345677) 40 days, 7:37:36.77 |
rs3@RS3:/usr/lib/nagios/plugins$ ./check_snmp -H 192.168.0.252 -C public -o sysUpTime.0 | awk F` ` `{ print $6 }`
-bash: command substitution: line 2: syntax error: unexpected end of file
rs3@RS3:/usr/lib/nagios/plugins$

Am I doing something a bit thick?
ASKER CERTIFIED SOLUTION
Avatar of Steve Jennings
Steve Jennings

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sjb79

ASKER

Hi Steve,

That worked, though I looked up awk on t'internet (never used awk before - hangs head in shame) and tweeked it a little;

 
define command{
        command_name    check_mainswitch_uptime
        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ -C $ARG1$ -o sysUpTime.0 | awk '{ print $6," days"}'
}

Open in new window


Cheers for that!

~Stephen