creating a perl Script to check service status

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
camacho12th
Posts: 1
Joined: Wed Oct 11, 2017 7:47 pm

creating a perl Script to check service status

Post by camacho12th »

Does anyone have a sample perl script for monitoring a service within /etc/int.d?

I've struggled to find one already made and now I must learn how to create one. This would really help me get my feet firmly on the ground.

Basically, I have an asterisk Service on a remote linux server that I want to make sure is running. If not, then generate a warning or critical.

Thank you greatly
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: creating a perl Script to check service status

Post by eloyd »

Just curious why you're not using the default "check_init_service" script to do that?
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: creating a perl Script to check service status

Post by tacolover101 »

eloyd wrote:Just curious why you're not using the default "check_init_service" script to do that?
perl 4 lyfe. this is a good question though.

Code: Select all

$s=(`service $ARGV[0] status`);
if ($s =~ '(running)') {
   $val1="is";
   $val2=1;
   }
else {
   $val1="is not";
   $val2=0;
   }
you'll need to get creative with how you leverage $ARGV[0] in a print command to define ok / warning / etc. could be written better, but there's a framework. logic could be written better, too.
kyang

Re: creating a perl Script to check service status

Post by kyang »

Locked