How to set threshold ranges for webinject check results?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
lavosgo
Posts: 6
Joined: Wed Apr 03, 2019 12:52 pm

How to set threshold ranges for webinject check results?

Post by lavosgo »

Hello All!

I need to know how to set up the WARNING/CRITICAL/OK ranges for the webinject plugin.

I'm getting this metrics output from a url http://mysite.com/metrics

{"results":{"CardMigration":{"fifteenMinuteRate":2.5198877460086915E-4,"fiveMinuteRate":2.536528315894611E-9,"oneMinuteRate":1.2007435063312563E-33,"meanRate":4.944581105531638E-4,"seventyFifthPercentile":1902.842522,"nintyFifthPercentile":1902.842522,"nintyNinthPercentile":1902.842522,"nintyNinePointNinePercentile":1902.842522,"max":2403.063908,"min":1154.246251,"mean":1902.7940546531531,"median":1902.842522,"count":3},"CardMigrationFailureRate":{"fifteenMinuteRate":0.0,"fiveMinuteRate":0.0,"oneMinuteRate":0.0,"meanRate":0.0,"count":0},"ReportCredentialMigration":{"fifteenMinuteRate":7.596007032787999E-4,"fiveMinuteRate":7.521494333847917E-9,"oneMinuteRate":3.915250950752425E-33,"meanRate":0.0013209614260733997,"seventyFifthPercentile":338.641369,"nintyFifthPercentile":338.641369,"nintyNinthPercentile":338.641369,"nintyNinePointNinePercentile":338.641369,"max":2028.339908,"min":8.363896,"mean":225.19234794089795,"median":328.545247,"count":8}

What I need to do is to set my alarms for some of this values:

For example:
CardMigration.meanRate needs to be lower than 1000 to be OK, greater than 1000 to be CRITICAL.
CardMigrationFailureRate.mean rate needs to be lower than CardMigration.meanRate to be OK, greater than CardMigration.meanRate to be CRITICAL

Overall what I have to monitor is the values like meanRate (also there are more meanRate values in metrics url) to be lower/higher than an specific number
User avatar
swolf
Developer
Posts: 294
Joined: Tue Jun 06, 2017 9:48 am

Re: How to set threshold ranges for webinject check results?

Post by swolf »

Hi @lavosgo,

I'm not sure how you would use webinject to monitor something like a JSON API. From my experience, webinject is used more for recording the user experience of a website.

In your situation, I would try something like check_json. If I'm reading the example usage correctly, your first check will look something like

Code: Select all

./check_json.pl --url http://mysite.com/metrics --attribute '{results}->{CardMigration}->{meanRate}' --warning :1000 --critical :1000 --perfvars '{results}->{CardMigration}->{meanRate},{results}->{CardMigrationFailureRate}->{meanRate}' 
This plugin won't be able to meet your second requirement, though. From what I'm seeing on the Exchange, you will probably need to write your own plugin if you want to check API endpoints against other endpoints.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy
lavosgo
Posts: 6
Joined: Wed Apr 03, 2019 12:52 pm

Re: How to set threshold ranges for webinject check results?

Post by lavosgo »

Hi @swolf,

I was using webinject because of the match logic that the plugin have as well as the simplicity of the plugin, having different test cases and case block was optimal for some other tests, but since now I need to match a dynamic value it became hard (tried to use regex to match values < than XXXX but no luck and don't know if possible).

So, can this check_json do the match to a value greater or lower than i.e 1000? (meanRate < 1000 = OK), Don't get it when you say about the second requirement.

Thanks!
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: How to set threshold ranges for webinject check results?

Post by mcapra »

lavosgo wrote:Don't get it when you say about the second requirement.
This requirement:
lavosgo wrote:CardMigrationFailureRate.mean rate needs to be lower than CardMigration.meanRate to be OK, greater than CardMigration.meanRate to be CRITICAL
Cannot be satisfied by check_json because check_json doesn't allow for comparison of arbitrary values/objects. It allows for the comparison of one value in the JSON body to a set of constants/thresholds.

It is worth mentioning the logic you requested in your OP doesn't actually match the JSON body you provided. There exists no CardMigrationFailureRate.mean value in that body.

This wouldn't be that tricky of a script to write, though. Cleaning up the body you provided a bit to be proper JSON:

Code: Select all

{
  "results": {
    "CardMigration": {
      "count": 3,
      "fifteenMinuteRate": 0.00025198877460086915,
      "fiveMinuteRate": 2.536528315894611E-9,
      "max": 2403.063908,
      "mean": 1902.7940546531531,
      "meanRate": 0.0004944581105531638,
      "median": 1902.842522,
      "min": 1154.246251,
      "nintyFifthPercentile": 1902.842522,
      "nintyNinePointNinePercentile": 1902.842522,
      "nintyNinthPercentile": 1902.842522,
      "oneMinuteRate": 1.2007435063312563E-33,
      "seventyFifthPercentile": 1902.842522
    },
    "CardMigrationFailureRate": {
      "count": 0,
      "fifteenMinuteRate": 0.0,
      "fiveMinuteRate": 0.0,
      "meanRate": 0.0,
      "oneMinuteRate": 0.0
    },
    "ReportCredentialMigration": {
      "count": 8,
      "fifteenMinuteRate": 0.0007596007032787999,
      "fiveMinuteRate": 7.521494333847917E-9,
      "max": 2028.339908,
      "mean": 225.19234794089795,
      "meanRate": 0.0013209614260733997,
      "median": 328.545247,
      "min": 8.363896,
      "nintyFifthPercentile": 338.641369,
      "nintyNinePointNinePercentile": 338.641369,
      "nintyNinthPercentile": 338.641369,
      "oneMinuteRate": 3.915250950752425E-33,
      "seventyFifthPercentile": 338.641369
    }
  }
}

As a simple Python script, with no exception handling, args, thresholds, or anything particularly fancy:

Code: Select all

import json
import requests

json_body = json.loads(requests.get('http://mysite.com/metrics').text)

if(float(json_body['results']['CardMigrationFailureRate']['mean']) > float(json_body['results']['CardMigrationRate']['meanRate'])):
    print('CRITICAL -- CardMigrationFailureRate.mean is greater than CardMigration.meanRate.')
    exit(2)
else: 
    print('OK -- CardMigrationFailureRate.mean is less than or equal to CardMigration.meanRate.')
    exit(0)
As Nagios plugin compatible outputs:

Code: Select all

# python test.py
CRITICAL -- CardMigrationFailureRate.mean is greater than CardMigration.meanRate.
# echo $?
2

# python test.py
OK -- CardMigrationFailureRate.mean is less than or equal to CardMigration.meanRate.
# echo $?
0
You could enhance this script to accept args, thresholds, handle connection failures, output performance data, etc. That's just a pretty basic example.
Former Nagios employee
https://www.mcapra.com/
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: How to set threshold ranges for webinject check results?

Post by cdienger »

Thanks @mcapra!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
lavosgo
Posts: 6
Joined: Wed Apr 03, 2019 12:52 pm

Re: How to set threshold ranges for webinject check results?

Post by lavosgo »

Hi guys, thank you all for the responses,

So I'm sorry to be asking this but, overall how can I do/complete all the requirements the easy way around.

The part of the Python script seems to be, for me, the best approach to this dilema but how can I implement that (as well as all my other checks) in nagios? Should I need to create a "Plugin" if so what is a good way to start? or where can I put those python scripts?

Sorry for the questions, I'm 99% noob on this.

Thanks!
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: How to set threshold ranges for webinject check results?

Post by cdienger »

A lot of plugins exist already so you shouldn't have to create a plugin for many of them. Creating a plugin is only needed if an existing plugin doesn't exist for what you need to do. Installed plugins are found in /usr/local/nagios/libexec/ and predefined plugin definitions are found in the GUI under Configure > Core Config Manager > Commands > _Commands.

Plugin management and integration is covered in https://support.nagios.com/kb/article/n ... i-235.html.

If you're interested in creating new plugins, check out:

https://assets.nagios.com/downloads/nag ... inapi.html
http://nagios-plugins.org/doc/guidelines.html
https://library.nagios.com/library/prod ... s-in-perl/
https://exchange.nagios.org/directory/T ... pt/details
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
lavosgo
Posts: 6
Joined: Wed Apr 03, 2019 12:52 pm

Re: How to set threshold ranges for webinject check results?

Post by lavosgo »

Hi!

Thanks for the info, but my question itself was "How can I /where should I implement @mcapara answer and how?

Thanks again!
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: How to set threshold ranges for webinject check results?

Post by cdienger »

You would copy the code that was provided(or create your own), save it to a file, and import it through the GUI. See https://support.nagios.com/kb/article/n ... i-235.html for details on where to import a plugin and how to integrate it with XI.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked