Resource Files - Macros

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Maxwellb99
Posts: 97
Joined: Tue Jan 26, 2016 5:29 pm

Resource Files - Macros

Post by Maxwellb99 »

Hello,

Hopefully a couple easy questions.

I added the NCPA token as a user macro to the resource file. When I run check_ncpa.py with the token it returns results but when I substitute the Macro it returns "error": "Incorrect credentials given."

Questions:
1. Where can I find the log that'll tell me what the macro is resolving as?
2. Do I need to restart anything after making changes to the resource file?
3. Are special characters from resource files stripped by default?
4. foo8?18bAr (not my actual token). The only line I added to resource.cfg was
4.a := $USER9$=foo8?18bAr
5. Do I need to include the path or is the syntax of my check given below correct?
5.a the difference between the first code block & the second is that the first includes the dollar signs $USER9$.

Code: Select all

[e132206@gcxsp0006 libexec]$ ./check_ncpa.py -H nrxav0089 -t $USER9$  -M 'memory/virtual/percent' -v
Connecting to: https://nrxav0089:5693/api/memory/virtual/percent/?token=%24&check=1
File returned contained:
{
  "error": "Incorrect credentials given."
}

Code: Select all

[e132206@gcxsp0006 libexec]$ ./check_ncpa.py -H nrxav0089 -t USER9 -M 'memory/virtual/percent' -v
Connecting to: https://nrxav0089:5693/api/memory/virtual/percent/?token=USER9&check=1
File returned contained:
{
  "error": "Incorrect credentials given."
}
An error occurred:'stdout'

Code: Select all

[e132206@gcxsp0006 libexec]$ ./check_ncpa.py -H nrxav0089 -t foo8?18bAr  -M 'memory/virtual/percent'
OK: Percent was 20.60 % | 'percent'=20.60%;;;
Thanks for your help.

Cheers,
Maxwell Ramirez
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Resource Files - Macros

Post by tmcdonald »

User macros do not work when you are testing a command manually on the command line. They only resolve properly within the context of a Nagios check, since it is the Nagios Core engine that is doing the replacement of $USER9$ with foo8?18bAr, for example. 99% of the time if you define a USER macro and use it in a check command, it will work when run by Nagios. The other 1% has to do with escaping characters properly, for the most part.

To answer your questions directly:

1.) This would need to be configured by setting the proper debug levels
2.) No
3.) I believe this would be dependent on the context, but in your case for a simple check I don't think this should be an issue
4.) The proper format is $USER9$=anycharacterscangohere (except newlines)
5.) I am not sure what path you are referring to - $USER9$ in your example seems to be referring to the NCPA token. You do need to include the $ signs when referring to a macro.

Further reading: https://assets.nagios.com/downloads/nag ... Macros.pdf
Former Nagios employee
Maxwellb99
Posts: 97
Joined: Tue Jan 26, 2016 5:29 pm

Re: Resource Files - Macros

Post by Maxwellb99 »

Hi,

Thanks for your quick reply. It's working Now.

I always try to get it working on the command line before I implement in Nagios. I would have been at it for a long time. I'm going to adjust the debug level & check that out. Please close this thread with my thanks.

Best Regards,
Maxwell Ramirez
Locked