Home: Perl Programming Help: Regular Expressions:
need help for nagiosgraph map file (perl script)



hendro
New User

Sep 19, 2006, 3:36 AM


Views: 17610
need help for nagiosgraph map file (perl script)

Hi,
I'm not programmer, but i want learn about perl.
I have a status informations that will generated to
nagiosgraph (map file) regexp.
Below is the status informations result from script:
1.Check_snmp_cisco_ifstatus => Status is OK -
Serial5/2 (PPP) - Current: 36 Kbps, Limit: 128 Kbps,
MTU: 1500, Last change: 244 days, 12:44:48.54,
STATS:(in errors: 483704, out errors: 2, queue length:
0)

2.Check_snmp_cisco_memutil => Status is OK - MEMORY:
total: 67.58 MB, used: 20.83 MB (31%), free: 46.75 MB

3.Check_snmp_cisco_loadavg => Status is OK - CPU load
average (5 min): 1 %



Best regards,


Hendro B


davorg
Thaumaturge / Moderator

Sep 19, 2006, 8:42 AM


Views: 17607
Re: [hendro] need help for nagiosgraph map file (perl script)

You don't appeared to have asked a question. How can we help you?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


hendro
New User

Sep 19, 2006, 11:30 PM


Views: 17604
Re: [davorg] need help for nagiosgraph map file (perl script)

#Cisco Mem util
#Status is OK - MEMORY: total: 67.58 MB, used: 20.84 MB (31%), free: 46.74 MB
/perfdata:Status.*?MEMORY:.*?total:.(\d+) MB.*? used: (\d+) MB \((\d+)\%\) free: (/d+\) MB.*? /
and push @s, [ Memutil,
[ total, GAUGE, $1 ],
[ used, GAUGE, $2 ],
[ free, GAUGE, $3 ] ];


#Cisco Loadavg
#Status is OK - CPU load average (5 min): 1 %
/perfdata:Status.*?CPU load average (5 min):.(\d+) %/
and push @s, [ Loadavg,
[ used, GAUGE, $1 ];

#Cisco Ifstatus
#Status is OK - Serial5/4 (PPP) - Current: 49 Kbps, Limit: 64 Kbps
/perfdata:Status.*?Serial.*?Current:.(\d+) Kbps, Limit: (\d+) Kbps
and push @s, [ Ifstatus,
[ current, GAUGE, $1 ],
[ limit, GAUGE, $2];


And the error message below:
Unmatched ( in regex; marked by <-- HERE in m/perfdata:Status.*?MEMORY:.*?total:.(\d+) MB.*? used: (\d+) MB \((\d+)%\) free: ( <-- HERE / at map.org line 65.

Could you help me.

Best regards

Hendro B


KevinR
Veteran


Sep 20, 2006, 12:01 AM


Views: 17602
Re: [hendro] need help for nagiosgraph map file (perl script)

I'm confused but.... in this line:


Code
/perfdata:Status.*?MEMORY:.*?total:.(\d+) MB.*? used: (\d+) MB \((\d+)\%\) free: (/d+\) MB.*? /


the last ')' is escaped with a '\' : (/d+\)
and the /d+ probably should be \d+

change the line to:


Code
/perfdata:Status.*?MEMORY:.*?total:.(\d+) MB.*? used: (\d+) MB \((\d+)\%\) free: (\d+) MB.*? /


or:


Code
/perfdata:Status.*?MEMORY:.*?total:\.(\d+) MB.*? used: (\d+) MB \((\d+)\%\) free: (\d+) MB.*? /

-------------------------------------------------


(This post was edited by KevinR on Sep 20, 2006, 12:01 AM)


hendro
New User

Sep 20, 2006, 1:27 AM


Views: 17599
Re: [KevinR] need help for nagiosgraph map file (perl script)

#This is the sample that working very well with deference services.
# Service type: ping
# output:PING OK - Packet loss = 0%, RTA = 0.00 ms
/output:PING.*?(\d+)%.+?([\d]+)\sms/
and push @s, [ "ping",
[ "losspct", GAUGE, $1 ],
[ "rta", GAUGE, $2/1000 ] ];


davorg
Thaumaturge / Moderator

Sep 20, 2006, 5:16 AM


Views: 17597
Re: [hendro] need help for nagiosgraph map file (perl script)

KevinR has spotted the problem, but I think it's worth explaining how Perl has told you what the problem is.

Your regex looks like this:

Code
/perfdata:Status.*?MEMORY:.*?total:.(\d+) MB.*? used: (\d+) MB \((\d+)\%\) free: (/d+\) MB.*? /


And the error message looks like this:


Quote
Unmatched ( in regex; marked by <-- HERE in m/perfdata:Status.*?MEMORY:.*?total:.(\d+) MB.*? used: (\d+) MB \((\d+)%\) free: ( <-- HERE


Perl tells you what the problem is - "Unmatched ( in regex" - and shows you exactly where the problem is.

So, going back to your regex, you have an unmatched opening parenthesis. Parentheses are special characters in regexes and have to come in matched pairs. Let's look at your regex, starting from the unmatched character:


Code
(/d+\) MB.*?


Well, there's a closing parenthesis character there, but it's escaped. So you have an opening parenthesis that is interpreted as a special character and a closing parenthesis that is escaped and is therefore interpreted literally (i.e. not as a special character.

So you need to decide what you're actually trying to do with that pair of parentheses. Are they supposed to be used as special characters or as literal characters?

Depending on which you choose, your regex should become:

Code
\(/d+\) MB.*?

or

Code
(/d+) MB.*?


Looking at your original data, it seems that the section of data that you're trying to match at this point doesn't have parentheses around it. So I bet that you meant to use the parentheses as special characters not as literals. So neither of them should be escaped. So the second option above is most likely to be what you need.

See, Perl gave you all the help it could. And the error message was actually really clear about what the problem is. You didn't need our help at all!

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


KevinR
Veteran


Sep 20, 2006, 6:42 AM


Views: 17596
Re: [hendro] need help for nagiosgraph map file (perl script)


In Reply To
#This is the sample that working very well with deference services.
# Service type: ping
# output:PING OK - Packet loss = 0%, RTA = 0.00 ms
/output:PING.*?(\d+)%.+?([\d]+)\sms/
and push @s, [ "ping",
[ "losspct", GAUGE, $1 ],
[ "rta", GAUGE, $2/1000 ] ];


Is the above supposed to mean something?
-------------------------------------------------


hendro
New User

Sep 20, 2006, 7:04 PM


Views: 17594
Re: [KevinR] need help for nagiosgraph map file (perl script)

Ok' thx for your help i get the point :)