Nagios, SNMPTT, AWK

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
mrninni
Posts: 27
Joined: Tue Sep 27, 2011 8:35 am

Nagios, SNMPTT, AWK

Post by mrninni »

Hi all,
I want to parse a text trap in order to send it to Nagios using SNMPTT.
I'm developing a AWK system using a configuration file like this:

Code: Select all

echo "CC Error - Serrenti TV - 0h00500" | awk -f file_configuration

file_configuration:
$0 ~ /ftv|reunion|mayotte|serrentitv|rad|libre64/        {print "W2M-D9"}
Before the parsing the text, i'd like to modify the $0 variable in order to remove all spaces and all uppercase chars:
CC Error - Serrenti TV - 0h00500 --> ccerror-serrentitv-0h00500

The command must return only one word: W2M-D9.

How i can do?
Thanks,
Marco
mrninni
Posts: 27
Joined: Tue Sep 27, 2011 8:35 am

Re: Nagios, SNMPTT, AWK

Post by mrninni »

Hi all, i found the way to remove all uppercases:

Code: Select all

echo "CC Error - Serrenti TV - 0h00500" | awk -f file_configuration

file_configuration:
tolower($0) ~ /ftv|reunion|mayotte|serrentitv|rad|libre64/        {print "W2M-D9"}
Now I need to remove all the spaces and return only the word W2M-D9.

Can anybody help me?
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: Nagios, SNMPTT, AWK

Post by jsmurphy »

If it's just white space you need to remove then regex is your friend, I don't know awk very well but something like:

$var =~ s/^\s+|\s+$//g;

I know awk has regex so you just need to find the syntax for an awk replace :)
Locked