?
Solved

Formatting snmp_check sysUpTime output

Posted on 2011-10-17
7
Medium Priority
?
2,120 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:sjb79
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:SteveJ
ID: 36986819
awk { print $6 }
0
 

Author Comment

by:sjb79
ID: 36986882
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?
0
 
LVL 16

Expert Comment

by:SteveJ
ID: 36986892
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
0
Cyber Threats to Small Businesses (Part 1)

This past May, Webroot surveyed more than 600 IT decision-makers at medium-sized companies to see how these small businesses perceived new threats facing their organizations.  Read what Webroot CISO, Gary Hayslip, has to say about the survey in part 1 of this 2-part blog series.

 
LVL 16

Expert Comment

by:SteveJ
ID: 36987181
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
0
 

Author Comment

by:sjb79
ID: 36987264
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?
0
 
LVL 16

Accepted Solution

by:
SteveJ earned 1000 total points
ID: 36987432
No . . . try leaving out the "F' '" and use ' not ` . . . like:

./check_snmp -H 192.168.0.252 -C public -o sysUpTime.0 | awk '{ print $6 }'


Steve
0
 

Author Comment

by:sjb79
ID: 36991896
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

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article, we’ll look at how to deploy ProxySQL.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question