Solved

How to monitor services running on Linux server under /etc/init.d ?


Badge +3

Hi team,

 

Is there a way to monitor a Linux service running under /etc/init.d  ?

I have many services running on my PBX and I need to monitor them on my Centreon:

 

 

Thank you

 

Regards

icon

Best answer by UC33260 26 June 2022, 21:48

View original

14 replies

Badge +3

Hi team,

 

Is there a way to monitor a Linux service running under /etc/init.d  ?

I have many services running on my PBX and I need to monitor them on my Centreon:

 

 

Thank you

 

Regards

 

Userlevel 5
Badge +17

Hi, 

 


The closest would be to use the process check:

/usr/lib/centreon/plugins//centreon_linux_snmp.pl --plugin=os::linux::snmp::plugin --mode=processcount --hostname=172.16.4.125 --snmp-version='2c' --snmp-community='public'  --process-name='mediamanager' --process-path='' --process-args='''' --regexp-name --regexp-path --regexp-args --warning='' --critical='1:1' --cpu --memory

 

You have to identify which process(es) are launched through /etc/init.d/ and then use it in the --process-name option

Badge +3

Sorry, I’m new on Centreon and I don’t understand how to use this code.

 

Do I need to use GUI interface or SSH ?  do you have a link to a ready example ?

 

Does this code allow me to receive the same command result ?

 

#Media Manager is running if OK and #Media manager is stopped if CRITICAL

 

Thank you

Badge +3

Here is my actual config:

  1. I created a command check:

 

I linked this command to my service:

 

 

The problem is: the output message is not good:

 

 

My service is running fine...

 

This script is to count the number of ruuning process

Userlevel 3
Badge +11

Hello,

You can't monitor service SysV /etc/init.d/ but you could monitor status of Systemd service but not in SNMP... and maybe because you use an old Distro you don't have Systemd to try to monitor status.

Linux SNMP Plugins provide : https://github.com/centreon/centreon-plugins/blob/7569cde979ecf5626df458bac15698105129367d/os/linux/snmp/plugin.pm#L33

Linux NRPE3 plugins provide : https://github.com/centreon/centreon-plugins/blob/7569cde979ecf5626df458bac15698105129367d/os/linux/local/plugin.pm#L33

With SNMP, you just add an Host like indicated on the documentation : https://docs.centreon.com/fr/docs/getting-started/monitor-linux-server-with-snmp/

But first you do add service template OS-Linux-SNMP-Process-Generic-Name-custom to your template OS-Linux-SNMP-custom, to be able to monitor the number of process who is named like your process.

After you could configure your service like indicated here (Just for the possibility and the menu) https://docs.centreon.com/fr/docs/monitoring/basic-objects/services/ and https://docs.centreon.com/fr/docs/monitoring/basic-objects/services-templates/ you just have to configure the service to custom it to your process name.

By this way you don't need to create a command, to create a service template and attach it, and create a Host template to attach the service template too and finally create your Host to deploy your Host template.

Otherwise you do create your command to check specifically the status of a SysV service, you could use Nagios Script on Nagios Exchange like here https://exchange.nagios.org/directory/Plugins/Network-and-Systems-Management/Unix-2FLinux-Check-Service-Status/details for exemple, but you do install NRPE agent on your Host and maybe adapt script usage to Centreon. It's not a standard way.

Badge +3

i’m running the latest Centreon release 22.04

Badge +3

Hi, I wrotten a shell script that return the state of my needed services.

 

But I don’t know how to implement my script with Centreon NRPE plugin.

 

An idea ?

 

here is my script:

 

###########################

#!/bin/bash                                                                                                               
                                                                                                                     
X="VoiceMail Pro is running"                                                                                              
Y="VoiceMail Pro is stopped"                                                                                              
                                                                                                                       
command=$(/etc/init.d/vmpro status | tee > /usr/lib/centreon/plugins/avaya_vmpro_out.txt)                                 

head -1 /usr/lib/centreon/plugins/avaya_vmpro_out.txt > /usr/lib/centreon/plugins/avaya_vmpro_out_2.txt

content=$(cat /usr/lib/centreon/plugins/avaya_vmpro_out_2.txt)

if [ "$X" == "$content" ]; then
        echo "OK, Voicemail Pro service is running"

                elif [ "$Y" == "$content" ]; then

                                echo "CRITICAL , Voicemail Pro service is stopped !!"
                                    else
                                        echo "UNKNOWN, etat du service inconnu, peut etre demarrage ou arret en cours"
fi

 

Thank you

Badge +3

I found a solution to implement my script with note on Centreon.

thanks 

I found a solution to implement my script with note on Centreon.

thanks 

 

I am interested in finding out more, what was your solution? 

Badge +3

I used the check_centreon_nrpe3 to call the script from /usr/lib/Centreon/plugins (the script that I wrote is mentioned on my previous reply.

you need to chmod the script and txt files to 777 to give centreon user the read and write right.

after that you need to create command check template and service host.

 

for more details, let me know, I can share config screenshots.

 

Badge +3

I tested the plugin NRPE3 with systemd status check:

 

 

systemctl don’t return the same result like /etc/init.d

 

I don’t know which argument I need to put on the service custom macro...

Userlevel 3
Badge +11

Hello,

Logically you don't have to add settings on macros about the threshold Critical and Warning Status.

Help about the mode indicate :

Check systemd services status.


Command used: 'systemctl -a --no-pager --no-legend' and 'systemctl list-unit-files --no-pager --no-legend'


=over 8


=item B<--filter-name>
Filter service name (can be a regexp).


=item B<--exclude-name>
Exclude service name (can be a regexp).


=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total-running', 'total-dead', 'total-exited',
'total-failed'.


=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{display}, %{active}, %{sub}, %{load}, %{boot}


=item B<--critical-status>
Set critical threshold for status (Default: '%{active} =~ /failed/i').
Can used special variables like: %{display}, %{active}, %{sub}, %{load}, %{boot}

Your service is in failed state (third lines of the result for systemctl status onexportal.service) it could be in CRITICAL state on Centreon.

Could you post the execution of the command ?

Regards

Userlevel 3
Badge +11

Command could be :

/usr/lib64/nagios/plugins/check_centreon_nrpe3 \
    -H x.x.x.x \
    -p 5666 -t 5 -u \
    -c check_centreon_plugins \
    -a 'os::linux::local::plugin' 'systemd-sc-status'  '  --statefile-dir=/var/log/nrpe/centplugins' ‘--filter-name=onexportal.service’

You execute this command on your poller maybe your central server with the Linux local account centreon-engine

Badge +3

Yes I found after some tests.

thank you 

Reply