CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



hendro
New User

Sep 19, 2006, 3:36 AM

Post #1 of 8 (10782 views)
need help for nagiosgraph map file (perl script) Can't Post

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

Post #2 of 8 (10779 views)
Re: [hendro] need help for nagiosgraph map file (perl script) [In reply to] Can't Post

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

Post #3 of 8 (10776 views)
Re: [davorg] need help for nagiosgraph map file (perl script) [In reply to] Can't Post

#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

Post #4 of 8 (10774 views)
Re: [hendro] need help for nagiosgraph map file (perl script) [In reply to] Can't Post

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

Post #5 of 8 (10771 views)
Re: [KevinR] need help for nagiosgraph map file (perl script) [In reply to] Can't Post

#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

Post #6 of 8 (10769 views)
Re: [hendro] need help for nagiosgraph map file (perl script) [In reply to] Can't Post

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

Post #7 of 8 (10768 views)
Re: [hendro] need help for nagiosgraph map file (perl script) [In reply to] Can't Post


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

Post #8 of 8 (10766 views)
Re: [KevinR] need help for nagiosgraph map file (perl script) [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives