Monitoring json values

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Monitoring json values

Post by DonForigua »

Hi

I try to use a json monitor with the wizzard

when i do a curl get the json exit

Code: Select all

[
  {
    "Telefono": {
      "id": "XXXXX",
      "name": "XXXXX",
      "selfUri": "/www/www/www/www"
    },
    "eventTime": "2021-12-16T00:23:32.646Z",
    "upTimeMsec": 340589000,
    "processors": [
      {
        "activeTimePct": 0,
        "cpuId": "total",
        "idleTimePct": 99,
        "privilegedTimePct": 0,
        "userTimePct": 0
      }
    ],
    "memory": [
      {
        "availableBytes": 5989015552,
        "type": "physical",
        "totalBytes": 8492802048
      },
      {
        "availableBytes": 14602121216,
        "type": "virtual",
        "totalBytes": 17254703104
      }
    ],
    "disks": [
      {
        "availableBytes": 463571476480,
        "partitionName": "C:",
        "totalBytes": 511374086144
      },
      {
        "availableBytes": 22169489408,
        "partitionName": "D:",
        "totalBytes": 32012754944
      }
    ],
    "subsystems": [
      {
        "delayMs": 0,
        "processName": "process1"
      },
      {
        "delayMs": 0,
        "processName": "process2",
        "mediaSubsystem": {
          "delayMs": 0,
          "processName": "process3"
        }
      },
      {
        "delayMs": 0,
        "processName": "process4"
      }
    ],
    "networks": [
      {
        "ifname": "{XXXXXXXXXXXXXXXX}",
        "sentBytesPerSec": 436,
        "receivedBytesPerSec": 534,
        "bandwidthBitsPerSec": 100000000,
        "utilizationPct": 0.0077599999494850636
      },
      {
        "ifname": "{XXXXXXXXXXXXXXXXXX}",
        "sentBytesPerSec": 0,
        "receivedBytesPerSec": 63,
        "bandwidthBitsPerSec": 100000000,
        "utilizationPct": 0.0005039999959990382
      }
    ]
  }
]
I need monitor many values

1. upTimeMsec > numeric value
2. processors > activeTimePct > numeric value
...
3. subsystems > processName > string vale (alert when it does not exists)

The wizzard has "Key" and i dont know how set it with the variables from json exit

thx for your help
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Monitoring json values

Post by benjaminsmith »

Hi Don.

The JSON Wizard has two main check types, strings or integers. The integer checks will have thresholds for warning and critical similar to other service checks in Nagios.

For string values, you can set the non-ok output for either the case of match or no match.

If you're having trouble getting it to match your values, please edit add the following at line 44 in check_json.php. This will allow us to see the array structure of the input data within the plugin.

Code: Select all

print_r($chDataArray);
Then run the check from the CLI and post the output to the thread. Thanks, Benjamin

Here's a sample check command against a REST API endpoint in Nagios XI.

Code: Select all

 php /usr/local/nagios/libexec/check_json.php -u 'https://192.168.23.113/nagiosxi/api/v1/objects/hoststatus?apikey=sCWXTQ3rHtm483AgRUUtLi04v5ECCVmktCCGoU8mINpPPflWafJbRKeGO8fGjUh6&host_name=localhost' -k hoststatus[0][host_object_id] -w 200 -c 250
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Monitoring json values

Post by DonForigua »

Hi here is the exit from the script

Code: Select all

Array                                                                                                                                                                                        
(                                                                                                                                                                                            
    [0] => Array                                                                                                                                                                             
        (                                                                                                                                                                                    
            [edge] => Array                                                                                                                                                                  
                (                                                                                                                                                                            
                    [id] => XXXXX                                                                                                                           
                    [name] => XXXXXXXXXXX                                                                                                                                                    
                    [selfUri] => XXXX                                                                                      
                )                                                                                                                                                                            
                                                                                                                                                                                             
            [eventTime] => 2021-12-16T21:18:38.919Z                                                                                                                                          
            [upTimeMsec] => 415896000                                                                                                                                                        
            [processors] => Array                                                                                                                                                            
                (                                                                                                                                                                            
                    [0] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [activeTimePct] => 0                                                                                                                                             
                            [cpuId] => total                                                                                                                                                 
                            [idleTimePct] => 100                                                                                                                                             
                            [privilegedTimePct] => 0                                                                                                                                         
                            [userTimePct] => 0                                                                                                                                               
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                )                                                                                                                                                                            
                                                                                                                                                                                             
            [memory] => Array                                                                                                                                                                
                (                                                                                                                                                                            
                    [0] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [availableBytes] => 5981577216                                                                                                                                   
                            [type] => physical                                                                                                                                               
                            [totalBytes] => 8492802048                                                                                                                                       
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                    [1] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [availableBytes] => 14595571712                                                                                                                                  
                            [type] => virtual                                                                                                                                                
                            [totalBytes] => 17254703104                                                                                                                                      
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                )                                                                                                                                                                            
                                                                                                                                                                                             
            [disks] => Array                                                                                                                                                                 
                (                                                                                                                                                                            
                    [0] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [availableBytes] => 463584665600                                                                                                                                 
                            [partitionName] => C:                                                                                                                                            
                            [totalBytes] => 511374086144                                                                                                                                     
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                    [1] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [availableBytes] => 22169489408                                                                                                                                  
                            [partitionName] => D:                                                                                                                                            
                            [totalBytes] => 32012754944                                                                                                                                      
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                )                                                                                                                                                                            
                                                                                                                                                                                             
            [subsystems] => Array                                                                                                                                                            
                (
                    [0] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [delayMs] => 0                                                                                                                                                   
                            [processName] => Process1                                                                                                                                
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                    [1] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [delayMs] => 0                                                                                                                                                   
                            [processName] => Process2                                                                                                                                 
                            [mediaSubsystem] => Array                                                                                                                                        
                                (                                                                                                                                                            
                                    [delayMs] => 0                                                                                                                                           
                                    [processName] => Process3                                                                                                                           
                                )                                                                                                                                                            
                                                                                                                                                                                             
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                    [2] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [delayMs] => 0                                                                                                                                                   
                            [processName] => Process4                                                                                                                                      
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                )                                                                                                                                                                            
                                                                                                                                                                                             
            [networks] => Array                                                                                                                                                              
                (                                                                                                                                                                            
                    [0] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [ifname] => {XXXXXXXXXXXXX}                                                                                                               
                            [sentBytesPerSec] => 430                                                                                                                                         
                            [receivedBytesPerSec] => 0                                                                                                                                       
                            [bandwidthBitsPerSec] => 100000000                                                                                                                               
                            [utilizationPct] => 0.0034399998839945                                                                                                                           
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                    [1] => Array                                                                                                                                                             
                        (                                                                                                                                                                    
                            [ifname] => {XXXXXXXXXXXXXXXX}                                                                                                               
                            [sentBytesPerSec] => 0                                                                                                                                           
                            [receivedBytesPerSec] => 63                                                                                                                                      
                            [bandwidthBitsPerSec] => 100000000                                                                                                                               
                            [utilizationPct] => 0.00050399999599904                                                                                                                          
                        )                                                                                                                                                                    
                                                                                                                                                                                             
                )                                                                                                                                                                            
                                                                                                                                                                                             
        )                                                                                                                                                                                    
                                                                                                                                                                                             
) 
Thx for your help
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Monitoring json values

Post by DonForigua »

Hi

another both of questions

1. can i autenticate the api via oauth 2

2. how can i set a values minor than 300 for uptime

Thanx for you help
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Monitoring json values

Post by benjaminsmith »

Hi Don,

Let's get some valid results coming back on the command line first, and then you can run the wizard again with the correct settings.

Looking at the output, it's a nested array, so try running the following and let me know that works. You can adjust the thresholds as needed, I just put in sample numbers.

Code: Select all

php /usr/local/nagios/libexec/check_json.php -u myurl -k [0][edge][upTimeMsec] -w 100 -c 200
Regarding your other questions. Oauth 2 authentication is not currently available. For the other question, can you clarify this one a little more. Not sure about the meaning of values minor?

Thanks,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Monitoring json values

Post by DonForigua »

Greetings

How can get the autorization bearer token with this plugun, i do:

Code: Select all

curl -k -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic BASE64USERandPassword" -d "grant_type=client_credentials" -X POST "https://login.mypurecloud.com/oauth/token"
it give me a bearer token

Code: Select all

{"access_token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXX","token_type":"bearer","expires_in":86399}
and how use it to autenticate the monitoring plugin.

thanks for your help
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Monitoring json values

Post by benjaminsmith »

Hi Don,

Try passing the header key, value pairs in the URL string as follows (testing from the command line), and let me know you are able to get data back.

Code: Select all

https://{username}:{password}@api-endpoint.com
https://access_tokent:{password}@api-endpoint.com
Regards,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Monitoring json values

Post by DonForigua »

Hello

In both cases i get

Code: Select all

napoles.XXXXXXX:/root> # php /usr/local/nagios/libexec/check_json.php -u 'https://XXXXXXXXXXXX:{XXXXXXXXXXXXX}@api.mypurecloud.com/api/v2/telephony/providers/edges/metrics?edgeIds=XXXXXXXXXXXXXXXXXX' -k 0.upTimeMsec -h -w 0 -c 300                        
Array                                                                                                                                                                  
(                                                                                                                                                                      
    [message] => No authentication bearer token specified in authorization header.                                                                                     
    [code] => authentication.required                                                                                                                                  
    [status] => 401                                                                                                                                                    
    [contextId] => 7121d1c9-c390-458c-89b6-fcf5ce962fa6                                                                                                                
    [details] => Array                                                                                                                                                 
        (                                                                                                                                                              
        )                                                                                                                                                              
                                                                                                                                                                       
    [errors] => Array                                                                                                                                                  
        (                                                                                                                                                              
        )                                                                                                                                                              
                                                                                                                                                                       
)                                                                                                                                                                      
UNKNOWN - Could not find the key or the value is not numeric                                                                                                           
Thx for your help
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Monitoring json values

Post by benjaminsmith »

Hi,

Thanks for testing that out. I just learned that there was recently an update to the script to be able to pass headers as an option. This is not shown in the GUI of the configuration wizard. It's in the latest (1.1.0) version of the JSON wizards
-u url
-k json key
-s treat key as a string
-r status code if <string> matches <key> value (defaults to 0 when -s used)
-n status code if <string> does not match <key> value (defaults to 2 when -s is used)
-c critical threshold
-w warning threshold
-h additional header add to request
So for example:

Code: Select all

php /usr/local/nagios/libexec/check_json.php -u 'https://api.mypurecloud.com/api/v2/telephony/providers/edges/metrics?edgeIds=XXXXXXXXXXXXXXXXXX' -h 'Header1:foo' -k 0.upTimeMsec -h -w 0 -c 300  
Let me know if that works. Make sure you update the configuration wizard.

See: https://assets.nagios.com/downloads/nag ... Web-UI.pdf
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Monitoring json values

Post by DonForigua »

Greetings

i've just updated the config wizzard to version 1.0.1

My problem is the bearer token is expiring each 24 hours.

must i ser manually it each 24 hours?

Code: Select all

curl -k -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXX" -d "grant_type=client_credentials" -X POST "https://login.mypurecloud.com/oauth/token"
it gives me a bearer that i set with -h parameter

Code: Select all

-h 'Authorization: bearer XXXXXXXXXXXXXXXXXX'
but it is a manual process :cry:

i need suport for oauth2 login in the plugin
Locked