Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Directory
oragain
byoragain, December 10, 2014
You can actually easily modify the script in order to retrieve values from the query. I modified mine to retrieve only one value:
in process_results, i changed $perfdata=.... to $perfdata = "value={$query_duration};0;"; There is no need for me to actually show static lines for warning and critical.
i initially did the change for query, but due to the complexity of the query, just better to go through a stored proc to dodge nagios / centreon cleanup string functions.
before the call to process_results i did the following changes that will allow you to retrieve a value for a procedure:
//Custom modification by #########
if ($querytype == "stored procedure") {
$stmt = mssql_init($oldstoredproc);
$query_data = mssql_execute($stmt);
$query_result="no result returned";
if (mssql_num_rows($query_data) > 0 ) {
$row = mssql_fetch_row($query_data);
$query_result = $row[0];
// cheating on process_results
$query_duration = $query_result;
$output_msg = "Value=$query_result.";
}
mssql_free_statement($stmt);
$exit_code = 0;
}
// end of custom
and at the beginning of the file, I changed to the following because mssql_execute does not need the exec part:
// Add "exec" to the beginning of the stored proc if it doesnt exist.
if (isset($storedproc)) {
$oldstoredproc = $storedproc;
if (substr($storedproc, 0, 5) != "exec ") {
$storedproc = "exec $storedproc";
}
}
in process_results, i changed $perfdata=.... to $perfdata = "value={$query_duration};0;"; There is no need for me to actually show static lines for warning and critical.
i initially did the change for query, but due to the complexity of the query, just better to go through a stored proc to dodge nagios / centreon cleanup string functions.
before the call to process_results i did the following changes that will allow you to retrieve a value for a procedure:
//Custom modification by #########
if ($querytype == "stored procedure") {
$stmt = mssql_init($oldstoredproc);
$query_data = mssql_execute($stmt);
$query_result="no result returned";
if (mssql_num_rows($query_data) > 0 ) {
$row = mssql_fetch_row($query_data);
$query_result = $row[0];
// cheating on process_results
$query_duration = $query_result;
$output_msg = "Value=$query_result.";
}
mssql_free_statement($stmt);
$exit_code = 0;
}
// end of custom
and at the beginning of the file, I changed to the following because mssql_execute does not need the exec part:
// Add "exec" to the beginning of the stored proc if it doesnt exist.
if (isset($storedproc)) {
$oldstoredproc = $storedproc;
if (substr($storedproc, 0, 5) != "exec ") {
$storedproc = "exec $storedproc";
}
}