Perl script integrating to NSclient++

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
bosco
Posts: 40
Joined: Thu Nov 24, 2016 5:34 am

Perl script integrating to NSclient++

Post by bosco »

Perl script integrating to NSclient++

Hi i have a Perl script for checking the date in a .ini file and service status and if not running will throw critical alert. i would like to know how to integrate that script in nsclient++.cfg file as i am first time using perl script and i know its similar to the pwershell integration,can you share from below which is the right method for intgrating this in nsclient++.cfg file

[/settings/external scripts/wrappings]
; Perl scripts
pl = "C:\\\\strawberry\\\\perl\\\\bin\\\\perl.exe" scripts\\\\%SCRIPT% %ARGS%


[External Scripts]
[...]
check_oracle_cman=perl scripts\check_oracle_cman.pl --mode="$ARG1$" --environment="C:\oracle\client11g"
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Perl script integrating to NSclient++

Post by mcapra »

The biggest obstacle is getting Perl to run correctly in the Windows environment. Does perl resolve correctly? What's the output from command prompt when you type:

Code: Select all

perl -v
It seems like you have set up a wrapper for .pl files:

Code: Select all

[/settings/external scripts/wrappings]
; Perl scripts
pl = "C:\\\\strawberry\\\\perl\\\\bin\\\\perl.exe" scripts\\\\%SCRIPT% %ARGS%
But aren't defining your perl script as a "wrapped script". In order for the wrapping to apply, you will need to define your external script under the "wrapped scripts" section like so:

Code: Select all

# A list of wrapped scripts (ie. script using a template mechanism).
[/settings/external scripts/wrapped scripts]
Refer to this section of the NSClient++ documentation to get your wrapping to apply to your .pl script:
https://docs.nsclient.org/reference/che ... ed-scripts
Former Nagios employee
https://www.mcapra.com/
bosco
Posts: 40
Joined: Thu Nov 24, 2016 5:34 am

Re: Perl script integrating to NSclient++

Post by bosco »

I have attached the perl script i am using,it works fine from the machine and give the result in output.txt(attached),now i want Perl script to be run from nagios by integrating to Nsclient.cfg,can you please see how this to bee added anything simialir to wehat i previously did for powershell

[/settings/external scripts/scripts]
check_file-exist = cmd /c echo scripts\filecheckps.ps1; exit($LastExitCode) | powershell.exe -command -

[/settings/external scripts/wrapped scripts]

pl = perl\bin\perl

[/settings/external scripts/scripts]
HWHP = "perl\\bin\\perl scripts\\check_hpasm.pl -H 127.0.0.1"

I drilled down this URL and could not find the apt one

https://docs.nsclient.org/howto/externa ... ower-shell

last got some info from this URL

https://www.thomas-krenn.com/de/wiki/In ... ntegrieren
Attachments
Output.txt
output
(219 Bytes) Downloaded 373 times
test.pl
perl script
(3.49 KiB) Downloaded 400 times
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Perl script integrating to NSclient++

Post by tgriep »

Try defining the command in the nsclient.ini like the following example and see if it works.

Code: Select all

HWHP = c:\strawberry\perl\bin\perl.exe  "C:\Program Files\NSClient++\check_hpasm.pl -H 127.0.0.1"
I think that the perl.exe is not in the path on the system, you need to put the full path in the command.
Be sure to check out our Knowledgebase for helpful articles and solutions!
bosco
Posts: 40
Joined: Thu Nov 24, 2016 5:34 am

Re: Perl script integrating to NSclient++

Post by bosco »

is there anyting which i can the last exit code from the perl script
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Perl script integrating to NSclient++

Post by tgriep »

In my test system, the exit code is returned to the Nagios system correctly using the example from my earlier post.
When you are running the check, what is the exit code you are receiving?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked