Perl script integrating to NSclient++

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Perl script integrating to NSclient++

Postby bosco » Fri Apr 21, 2017 4:00 am

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"
bosco
 
Posts: 16
Joined: Thu Nov 24, 2016 5:34 am

Re: Perl script integrating to NSclient++

Postby mcapra » Fri Apr 21, 2017 1:10 pm

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
Be sure to check out our Knowledgebase for helpful articles and solutions!

https://github.com/mcapra/
User avatar
mcapra
Support Tech
 
Posts: 2310
Joined: Thu May 05, 2016 3:54 pm
Location: Nagios Enterprises

Re: Perl script integrating to NSclient++

Postby bosco » Wed Apr 26, 2017 4:33 am

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 4 times
test.pl
perl script
(3.49 KiB) Downloaded 4 times
bosco
 
Posts: 16
Joined: Thu Nov 24, 2016 5:34 am

Re: Perl script integrating to NSclient++

Postby tgriep » Wed Apr 26, 2017 3:33 pm

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!
User avatar
tgriep
Madmin
 
Posts: 4593
Joined: Thu Oct 30, 2014 9:02 am

Re: Perl script integrating to NSclient++

Postby bosco » Thu Apr 27, 2017 3:59 am

is there anyting which i can the last exit code from the perl script
bosco
 
Posts: 16
Joined: Thu Nov 24, 2016 5:34 am

Re: Perl script integrating to NSclient++

Postby tgriep » Thu Apr 27, 2017 9:58 am

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!
User avatar
tgriep
Madmin
 
Posts: 4593
Joined: Thu Oct 30, 2014 9:02 am


Return to Nagios Core

Who is online

Users browsing this forum: Bing [Bot] and 7 guests