1

Here I am trying to use a plugin to check whether the service running or not, if there is any warning or any critical action required, at the same time the performance parameter.

We have used below plugin to check if a server is alive or not and read it's performance data JSON https://github.com/drewkerrigan/nagios-http-json

I am trying to read a JSON file as below which is hosted on http://localhost:8080/sample.json

The plugin works perfectly on Command line, it shows me all the Metrics available.

$:/usr/lib/nagios/plugins$ ./check_http_json.py -H localhost:8080 -p sample.json -m metrics.etp_count metrics.atc_count

OK: Status OK.|'metrics.etp_count'=101 'metrics.atc_count'=0 

But when I try the same in Icinga2 configuration, it doesn't show me this performance metrics, although it doesn't give any error but at the same time it don't show any value.

find the JSON, Command.conf and Service.conf as follows.

{ 
 "metrics": {
    "etp_count": "0",
    "atc_count": "101",
    "mean_time": -1.0,
  }
}

Below are my commands.conf and services.conf

commands.conf

   /* Json Read Command */
object CheckCommand "json_check"{
import "plugin-check-command"
command = [PluginDir + "/check_http_json.py"]
arguments = {
"-H" = "$server_port$"
"-p" = "$json_path$"
"-w" = "$warning_value$"
"-c" = "$critical_value$"
"-m" = "$Metrics1$,$Metrics2$"
}
}

services.conf

apply Service "json"{
        import "generic-service"

        check_command = "json_check"
        vars.server_port="localhost:8080"
        vars.json_path="sample.json"
        vars.warning_value="metrics.etp_count,1:100"
        vars.critical_value="metrics.etp_count,101:1000"
        vars.Metrics1="metrics.etp_count"
        vars.Metrics2="metrics.atc_count"

        assign where host.name == NodeName
}

Does any one have any idea how can we pass multiple values in Command.conf and Service.conf??

Ravi Jain
  • 11
  • 1

1 Answers1

0

I have resolved the issue.

I had to change the Plugin file "check_http_json.py" for below code

def checkMetrics(self):
                """Return a Nagios specific performance metrics string given keys and parameter definitions"""
                metrics = ''
                warning = ''
                critical = ''
                if self.rules.metric_list != None:

                      for metric in self.rules.metric_list:

Replaced With

def checkMetrics(self):
                """Return a Nagios specific performance metrics string given keys and parameter definitions"""
                metrics = ''
                warning = ''
                critical = ''
                if self.rules.metric_list != None:

                        for metric in self.rules.metric_list[0].split():

Actually the issue was the list was not handled properly, so it was not able to iterate through the items in the list, it was considering it as a single string due to services.config file.

it had to be further get split to get the items in the Metrics string.

Ravi Jain
  • 11
  • 1