Page 1 of 1

How to set threshold ranges for webinject check results?

Posted: Thu Apr 04, 2019 3:37 pm
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

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

Posted: Fri Apr 05, 2019 10:15 am
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.

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

Posted: Fri Apr 05, 2019 11:43 am
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!

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

Posted: Fri Apr 05, 2019 1:49 pm
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.

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

Posted: Fri Apr 05, 2019 2:14 pm
by cdienger
Thanks @mcapra!

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

Posted: Sat Apr 06, 2019 10:31 pm
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!

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

Posted: Mon Apr 08, 2019 1:16 pm
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

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

Posted: Tue Apr 09, 2019 11:58 am
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!

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

Posted: Tue Apr 09, 2019 4:33 pm
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.