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