Page 1 of 1

Character "\" inserted into regex on save - check_ncpa.py

Posted: Wed May 22, 2019 2:36 pm
by dfaenza
Good afternoon,
I am having an issue with setting up a service check using check_ncpa.py. I am using a match=regex to monitor the services on a remote host for a series of SQL Anywhere databases, however I am trying to filter out any that are ending with "Training". I have the check working when I do a "Run Check Command", however when I go to save the check settings to apply in the configuration I have noticed that a "\" is automatically being inserted in my regex.

Here is the regex that is working:

-t '<<token>>' -P 5693 -M services -q match=regex,service='(^SQL)(?!.*Training).*'

However when I save the check, the below parameters are what is saved:

-t '<<token>>' -P 5693 -M services -q match=regex,service='(^SQL)(?\!.*Training).*'

I've not been able to locate any information in the NCPA documentation indicating why the character is being entered and was hoping that the forum might offer some additional information.

Nagios XI Version is 5.5.11
check_ncpa.py version is 1.1.3
NCPA Version is 2.1.6

Re: Character "\" inserted into regex on save - check_ncpa.p

Posted: Wed May 22, 2019 4:09 pm
by scottwilkerson
! is a special char in nagios for the check_command line in the configurations and needs to be escaped

See
https://support.nagios.com/kb/article.php?id=580

notably
The reason for the error this time has to do with the !. Nagios uses the ! as an argument separator. What you need to do is escape the ! with a \ so Nagios knows it should be plain text, for example:

Re: Character "\" inserted into regex on save - check_ncpa.p

Posted: Thu May 23, 2019 9:46 am
by dfaenza
@scottwilkerson, Thank you for the quick response. Something that I forgot to mention is that the regex with the escape character left out is working to find the services I need, however when the escape character is entered I receive an internal server error. I understand that I'll need to escape the special character in some way, however I'm not understanding why it works when not escaped, however breaks the check when it is escaped. Are you able to expand on that a little? I have tried escaping the "!" like so "\!" as well as "\!!" however neither are working currently.

I'm a bit confused. :?

Re: Character "\" inserted into regex on save - check_ncpa.p

Posted: Thu May 23, 2019 11:17 am
by SteveBeauchemin
I had this issue before.

This may help you work around the constraint.

In /usr/local/nagios/etc/resource.cfg add:

Code: Select all

#Escaping exclamation points
$USER9$=!
Then, in your service definition in the gui, use $USER9$ instead of the ! character.

Code: Select all

-t '<<token>>' -P 5693 -M services -q match=regex,service='(^SQL)(?!.*Training).*'
becomes

Code: Select all

-t '<<token>>' -P 5693 -M services -q match=regex,service='(^SQL)(?$USER9$.*Training).*'
Good Luck

Steve B

Re: Character "\" inserted into regex on save - check_ncpa.p

Posted: Thu May 23, 2019 4:32 pm
by scottwilkerson