Page 1 of 1

Nagios, SNMPTT, AWK

Posted: Tue Nov 15, 2011 5:05 am
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

Re: Nagios, SNMPTT, AWK

Posted: Wed Nov 16, 2011 9:32 am
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?

Re: Nagios, SNMPTT, AWK

Posted: Wed Nov 16, 2011 5:45 pm
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 :)