- Nagios Network Monitoring
- General Information and TidBits
- Installation Tips & Tricks
- Addons, Plugins, Tweaks & Customizations
- Checking Drupal Status with Nagios and WebInject
- AddOn - NRPE / NSClient
- AddOn - Nagios Event Log aka NagEventLog
- Addon - Nagios Passive Checks with NSCA
- Nagios Custom Object Variables
- Nagios Event Handler - Restart Remote Service
- Nagios Event Handler - Restarting a Local Service
- Plugin: check_dns_secondary - Checking NS Servers
- Plugin: check_http_requisites - Page Size, Files, and Loadtime
- Plugin: check_mem - Linux Memory Usage
- Plugin: check_sql - Check MSSQL and MYSQL servers
- Plugin: check_svn - Check Subversion
- Tweak - Nagios Jabber / XMPP Notifications
- Tweak - Nagios SMS Messaging
- Tweak - check_file_age to check_file_modified
- Tweak: Using NagiosGraph's SHOW.CGI
- Tweak: check_sql - Allow decimal values
- Common Errors & Fixes
Tweak: check_sql - Allow decimal values
- References:
While building another stored procedure that I execute by check_mssql in Nagios, I noticed a little hiccup. My stored procedure was returning a value like "85.67". When I executed the check_sql on the command line to run the procedure, I got a strange error...
# ./check_mssql -H mssqlclus1 -U username -P password -p 1433 -D database -w 20 -c 35 \ > -q "exec database.dbo.sp_GetDatabaseFileMetrics database,Used,Log,1" -W 90.00 -C 95.00 -s CHECK_MSSQL CRITICAL - Result is not numeric with result threshold defined (0.089992 seconds) \ | time=0.089992s;20;35
Now that does not make sense at all. I removed the -W and -C constraints and got:
CHECK_MSSQL OK - SQL Server result: 98.10 (0.122316 seconds) | time=0.122316s;20;35
I do not know about you, but "98.10" looks like a numeric to me. So I opened up the perl for the check_mssql and looked for the conditions that triggered the error. This was the regular expression it was evaluating to determine if the value returned was a numeric instead of a string.
$result =~ /^[-+]?\d+$/
Well, that does not do the trick if I have a value like "98.10". A value of "98" would have been fine. I freely admit I am no "code guru" by any means, but I figured I shoudl be able to come up with a fix for this. I copied the stored procedure to 'check_mssql2' and went to work. I created an OR condition to look for the integer regular expression or a decimal regular expression. There may be a better way, but this worked for me. I changed this:
!($result =~ /^[-+]?\d+$/)) {
to this:
!(($result =~ /^[-+]?\d+$/) || ($result =~ /^[-+]?\d+\.\d+$/))) {
I ran my tests and it worked great! A really useful link I found was this Regular Expression Validator at http://www.sweeting.org/mark/html/revalid.php. It also has some very handy reference info on the bottom which I found useful since I do not have the pleasure of writing them on a daily basis.
- Printer-friendly version
- Login or register to post comments
-

Recent comments
7 weeks 3 days ago
24 weeks 6 days ago
28 weeks 5 hours ago
37 weeks 6 days ago
45 weeks 2 days ago
45 weeks 4 days ago
50 weeks 1 day ago
1 year 1 week ago