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.
mrninni
Posts: 27 Joined: Tue Sep 27, 2011 8:35 am
Post
by mrninni » Tue Nov 15, 2011 5:05 am
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
Post
by mrninni » Wed Nov 16, 2011 9:32 am
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?
jsmurphy
Posts: 989 Joined: Wed Aug 18, 2010 9:46 pm
Post
by jsmurphy » Wed Nov 16, 2011 5:45 pm
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