Enhancements and fixes for check_mssql 0.8.3

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
mopp
Posts: 64
Joined: Thu Aug 20, 2015 7:15 am

Enhancements and fixes for check_mssql 0.8.3

Post by mopp »

Hello,

the https://exchange.nagios.org/directory/P ... ql/details has a bug, it does not support changing the port.
In addition in some cases query_result might not be initialized and return an error.
Both were fixed in addition I added a custom warning message:

Code: Select all

--- /usr/local/nagios/libexec/check_mssql       2018-03-20 15:26:28.000000000 +0100
+++ /tmp/check_mssql    2018-03-21 16:21:31.712496152 +0100
@@ -146,6 +146,10 @@
 $warning = "";
 $critical = "";
 $output_msg = "";
+$warn_msg = "Q_TYPE result Q_RESULT was higher than Q_TYPE warning threshold Q_WARNING.";
+$crit_msg = "Q_TYPE result Q_RESULT was higher than Q_TYPE warning threshold Q_CRITICAL.";
+$expected_msg = 'Query expected "EXP_RESULT" but got "Q_RESULT".';
+$query_result = "";
 $longquery = "";
 $long_output = "";

@@ -247,6 +251,18 @@
             $query_critical = check_command_line_option($_SERVER["argv"][$i], $i);
         break;

+        case '--warnmsg':
+            $warn_msg = check_command_line_option($_SERVER["argv"][$i], $i);
+        break;
+
+        case '--critmsg':
+            $crit_msg = check_command_line_option($_SERVER["argv"][$i], $i);
+        break;
+
+        case '--expmsg':
+            $expected_msg = check_command_line_option($_SERVER["argv"][$i], $i);
+        break;
+
         case '-w':
         case '--warning':
             $warning = check_command_line_option($_SERVER["argv"][$i], $i);
@@ -437,7 +453,7 @@
 $db_dsn_host = "host={$db_host}";
 if (!empty($db_inst)) {
     $db_dsn_host .= "\\{$db_inst}";
-} else if (!empty($port)) {
+} else if (!empty($db_port)) {
     $db_dsn_host .= ":{$db_port}";
 }
 $db_dsn = "dblib:{$db_dsn_host};dbname={$db_name}";
@@ -518,7 +534,10 @@
             case 1:
                 $state = "WARNING";
                 $exit_code = 1;
-                $output_msg = "$querytype result $query_result was higher than $querytype warning threshold $query_warning.";
+                $warn_msg = str_replace('Q_TYPE', "$querytype", $warn_msg);
+                $warn_msg = str_replace('Q_RESULT', "$query_result", $warn_msg);
+                $warn_msg = str_replace('Q_WARNING', "$query_warning", $warn_msg);
+               $output_msg = "$warn_msg";
         }
     }

@@ -534,7 +553,10 @@
             case 1:
                 $exit_code = 2;
                 $state = "CRITICAL";
-                $output_msg = "$querytype result $query_result was higher than $querytype critical threshold $query_critical.";
+                $crit_msg = str_replace('Q_TYPE', "$querytype", $crit_msg);
+                $crit_msg = str_replace('Q_RESULT', "$query_result", $crit_msg);
+                $crit_msg = str_replace('Q_CRITICAL', "$query_warning", $crit_msg);
+               $output_msg = "$crit_msg";
         }
     }

@@ -545,7 +567,9 @@
         } else {
             $exit_code = 2;
             $state = "CRITICAL";
-            $output_msg = "$querytype expected \"$expected_result\" but got \"$query_result\".";
+            $expected_msg = str_replace('Q_RESULT', "$query_result", $expected_msg);
+            $expected_msg = str_replace('EXP_RESULT', "$expected_result", $expected_msg);
+            $output_msg = "$expected_msg";
         }
     }
 }
@@ -719,6 +743,12 @@
     -c, --critical      Critical threshold in seconds on duration of check
     -W, --querywarning  Query warning threshold
     -C, --querycritical Query critical threshold
+    --warnmsg           Warning message (macros Q_RESULT, Q_TYPE, Q_WARNING), e. g.
+                        Q_TYPE result Q_RESULT was higher than Q_TYPE warning threshold Q_WARNING.
+    --critmsg           Critical message (macros Q_RESULT, Q_TYPE, Q_CRITICAL), e. g.
+                        Q_TYPE result Q_RESULT was higher than Q_TYPE warning threshold Q_CRITICAL.
+    --expmsg            Expected result message (macros Q_RESULT and EXP_RESULT), e. g.
+                        Query expected "EXP_RESULT" but got "Q_RESULT"

 Example: $progname -H myserver -U myuser -P mypass -q /tmp/query.sql -c 10 -W 2 -C 5
 Example: $progname -H myserver -U myuser -P mypass -q "SELECT COUNT(*) FROM mytable" -r "632" -c 10 -W 2 -C 5
If the code is okay, I would be happy if you can implement it.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Enhancements and fixes for check_mssql 0.8.3

Post by npolovenko »

Thank you, @mopp! I passed your code to our Dev Team. If you don't hear back from us by the end of the week feel free to PM me or post again in this thread.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Enhancements and fixes for check_mssql 0.8.3

Post by npolovenko »

There is a 0.8.4 version of this plugin that fixes the port issue. Please go to the Admin menu, then click on Manage Config Wizards in the left column. In the wizards menu click on:

1) Check for Updates
2)Install Updates

That should update your MSSQL Query to the version 1.6.4, and the plugin itself to the version 0.8.4.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
mopp
Posts: 64
Joined: Thu Aug 20, 2015 7:15 am

Re: Enhancements and fixes for check_mssql 0.8.3

Post by mopp »

I applied the update and I think I found another problem with the update service.
If the file /usr/local/nagios/libexec/ is not writeable by the webserver then itnot be replaced, which is okay. But the update service will show a OK message because the update of /usr/local/nagiosxi/html/includes/configwizards/mssql_query was successful.

Hopefully we will also get the enhancement with the custom message for check_mssql.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Enhancements and fixes for check_mssql 0.8.3

Post by npolovenko »

Hi, @mopp. Do you mean the libexec folder doesn't have writable permissions or the plugin? We checked a few servers in the lab and all had writable permissions.
I submitted a custom message feature request. Could you also provide a use case so I can add it in the comment?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
mopp
Posts: 64
Joined: Thu Aug 20, 2015 7:15 am

Re: Enhancements and fixes for check_mssql 0.8.3

Post by mopp »

Of course in a clean installation it will work, but for example in my case I worked on the check_mssql and as I copied the file as root to this libexec directory the permissions have changed.
If you always work with the web interface I don't expect any problems, but if you work on the system you might change the permissions on purpose or by accident.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Enhancements and fixes for check_mssql 0.8.3

Post by npolovenko »

@mopp, I see. I don't think there's any verification in place right now, but it's a good idea to have one. I submitted a feature request on your behalf.
Please keep in mind that the decision to implement the enhancement is at the discretion of our development team.
What about a use case for a custom message?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
mopp
Posts: 64
Joined: Thu Aug 20, 2015 7:15 am

Re: Enhancements and fixes for check_mssql 0.8.3

Post by mopp »

Sorry for the delay.
A custom message could be very helpful if you send the message to end user, e. g. you can write them a message what do to do, like "10 items are in the machine, please remove them".
Or if you have a lower threshold using --querycritical 100:, you will get a message with the threshold is higher, which is wrong.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Enhancements and fixes for check_mssql 0.8.3

Post by npolovenko »

Welcome back, @mopp.
If you have a lower threshold using --querycritical 100:, you will get a message with the threshold is higher, which is wrong.
This works as expected for me. With "--querycritical 2000" the result needs to be less than 2000, and with "--querycritical 2000:" the result needs to be bigger than 2000.

Code: Select all

/usr/local/nagios/libexec/check_mssql -H xxxxx --username admin --password "xxxxx" --database master --instance BRIMSTONE --query "SELECT+COUNT%28%2A%29+FROM+sys.sysperfinfo" --result "1008" --decode  --querycritical 2000

OK: Query duration=0.000643 seconds. Query result=1008|query_duration=0.000643s;; 'computed0'=1008;2000

Code: Select all

[root@centos7x64 libexec]# /usr/local/nagios/libexec/check_mssql -H xxxxx --username admin --password "xxxxx" --database master --instance BRIMSTONE --query "SELECT+COUNT%28%2A%29+FROM+sys.sysperfinfo" --result "1008" --decode  --querycritical 2000:

CRITICAL: Query result 1008 was higher than query critical threshold 2000:.|query_duration=0.0009s;; 'computed0'=1008;2000:
And as far as your suggestions to implement a custom message in arguments I passed it forward to our devs team.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
mopp
Posts: 64
Joined: Thu Aug 20, 2015 7:15 am

Re: Enhancements and fixes for check_mssql 0.8.3

Post by mopp »

Hi,

It is not about the functionality, which is fine. It is about the message itself.
CRITICAL: Query result 1008 was higher than query critical threshold 2000:.|query_duration=0.0009s;; 'computed0'=1008;2000:
From a plugin perspective the message is okay, the value 1008 is higher than 2000: (and follows the standard syntax https://nagios-plugins.org/doc/guidelin ... HOLDFORMAT).
But if you send the message to a "non IT guy" or "non monitoring guy", he will not understand why 1008 is higher than 2000:. As 1008 is not higher than 2000, you have to understand that 2000: means lower.

That is why I would like to have a custom message as I have posted in my code. So you can modify the message in a way the receiver of the emails will understand the problem.
Locked