sjb79
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;
Is there a way of just getting the days value of out this result so I can then set warning and critical levels?
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$
Is there a way of just getting the days value of out this result so I can then set warning and critical levels?
awk { print $6 }
ASKER
So the command would look like the following;
check_snmp -H 192.168.0.252 -C public -o sysUpTime.0 awk { print $6 }
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
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
You need a "pipe" after the check_snmp command
Test it . . .
Steve
ASKER
Tried and got this;
rs3@RS3:/usr/lib/nagios/pl ugins$ ./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/pl ugins$ ./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/pl ugins$
Am I doing something a bit thick?
rs3@RS3:/usr/lib/nagios/pl
SNMP OK - Timeticks: (348345677) 40 days, 7:37:36.77 |
rs3@RS3:/usr/lib/nagios/pl
-bash: command substitution: line 2: syntax error: unexpected end of file
rs3@RS3:/usr/lib/nagios/pl
Am I doing something a bit thick?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
Cheers for that!
~Stephen
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"}'
}
Cheers for that!
~Stephen