Failed to Start Nagios service

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.
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Failed to Start Nagios service

Post by Ravikimt »

Hi All,

I have installed nagios-4.4.1 version on my Ubuntu 18.04 LTS. Everything look fine but I am only getting below mentioned error while starting my Nagios service can anyone help me on this how I can get rid of this problem.

Code: Select all

● nagios.service - Nagios Core 4.4.1
   Loaded: loaded (/lib/systemd/system/nagios.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2018-11-29 14:06:12 UTC; 3s ago
     Docs: https://www.nagios.org/documentation
  Process: 19402 ExecStopPost=/bin/rm -f /usr/local/nagios/var/rw/nagios.cmd (code=exited, status=0/SUCCESS)
  Process: 19391 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
  Process: 19390 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
 Main PID: 19401 (code=exited, status=1/FAILURE)

Nov 29 14:06:12 Nginx-Backup nagios[19390]: Total Errors:   0
Nov 29 14:06:12 Nginx-Backup nagios[19390]: Things look okay - No serious problems were detected during the pre-flight check
Nov 29 14:06:12 Nginx-Backup systemd[1]: Started Nagios Core 4.4.1.
Nov 29 14:06:12 Nginx-Backup nagios[19401]: Nagios 4.3.4 starting... (PID=19401)
Nov 29 14:06:12 Nginx-Backup nagios[19401]: Local time is Thu Nov 29 14:06:12 UTC 2018
Nov 29 14:06:12 Nginx-Backup systemd[1]: nagios.service: Main process exited, code=exited, status=1/FAILURE
Nov 29 14:06:12 Nginx-Backup nagios[19401]: LOG VERSION: 2.0
Nov 29 14:06:12 Nginx-Backup systemd[1]: nagios.service: Failed with result 'exit-code'.
Nov 29 14:06:12 Nginx-Backup nagios[19401]: [u]qh: Failed to init socket '/usr/local/nagios/var/rw/nagios.qh'. unlink() failed: Permission denied[/u]
Nov 29 14:06:12 Nginx-Backup nagios[19401]: Error: Failed to initialize query handler. Aborting
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Failed to Start Nagios service

Post by scottwilkerson »

Looks like there is an issue with this file:

Code: Select all

ls -l /usr/local/nagios/var/rw/nagios.qh
If it exists you may need to delete the file and try starting nagios again
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Failed to Start Nagios service

Post by Ravikimt »

@scottwilkerson Thanks for the help. The previous issue got resolved but Now I am facing the another issue. I am not getting any error while running pre-flight check command for the nagios.cfg file

I am getting below mentioned error in nagios.log. Please help me here because it's not triggering the alerts

Code: Select all

[1544442429] wproc:   stderr line 01: /bin/sh: 1: /usr/bin/sendEmail: not found
[1544442429] wproc:   stderr line 02: /usr/bin/printf: write error: Broken pipe
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Failed to Start Nagios service

Post by tgriep »

The error is coming from the commands that send the email notifications and it looks like the sendEmail command is not installed so run this to install it.

Code: Select all

apt install sendemail
If it still fails, can you post your Nagios commands file so we can check the syntax for the mailer commands?

Code: Select all

/usr/local/nagios/etc/objects/commands.cfg
Thanks
Be sure to check out our Knowledgebase for helpful articles and solutions!
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Failed to Start Nagios service

Post by Ravikimt »

@tgriep Thanks for the help now I am getting below error after installing sendemail. It's showing me "Authentication not supported by the remote SMTP server!"

But the same SMTP server credential I am using somewhere else and it's working fine. I am suspecting that it's a not configuration issue please share your thought on the same.

Code: Select all

[1544614007] wproc:   stdout line 01: Dec 12 11:26:40 nginx-backup sendEmail[7021]: NOTICE => Authentication not supported by the remote SMTP server!
[1544614007] wproc:   stdout line 02: Dec 12 11:26:45 nginx-backup sendEmail[7021]: ERROR => Received:  530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [BYAPR11CA0100.namprd11.prod.outlook.com]
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Failed to Start Nagios service

Post by tgriep »

Couple of thing to check. See if the SMTP server has a filter that only allows certain hosts or certain IP addresses to forward emails through it.
Another thing, if the Nagios server is not supplying a valid from address, the SMTP server may block the emails as well so make sure that is set in the email notify command on the Nagios server.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Failed to Start Nagios service

Post by Ravikimt »

Hi tgriep, Firstly we don't have any mail server, we are using "smtp.office365.com" to send the emails we don't have suck any kind of options there "Only allows certain hosts or certain IP addresses to forward emails through ".

I verified that nagios server is supplying a valid from address. Still I am facing the same issue attaching email notify command for your reference.

resource.cfg file

Code: Select all

$USER1$=/usr/local/nagios/libexec

Code: Select all

$USER5$=nagios@xyz.com-email

Code: Select all

$USER6$=password

Code: Select all

$USER7$=smtp.office365.com

command.cfg

Code: Select all

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/sendEmail -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n\nNote: This is an automated message that is system generated so please do not reply to this email. For any queries write to 'tech.support@xyz.com'"

Code: Select all

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/sendEmail -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nNote: This is an automated message that is system generated so please do not reply to this email. For any queries write to 'tech.support@xyz.com'"
        }
Please help me here to solve this issue.
danjoh
Posts: 73
Joined: Mon Dec 07, 2015 10:43 am
Location: Zürich, Switzerland
Contact:

Re: Failed to Start Nagios service

Post by danjoh »

I do not know sendEmail, but checking the Web (http://caspian.dotconf.net/menu/Software/SendEmail/) it looks like you can specify the message body using the -m parameter (which you have...) and then you probable do not need the " /usr/bin/printf "%b ..." part.

So I would try something like this:

Code: Select all

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/sendEmail -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n\nNote: This is an automated message that is system generated so please do not reply to this email. For any queries write to 'tech.support@xyz.com'"

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/sendEmail -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nNote: This is an automated message that is system generated so please do not reply to this email. For any queries write to 'tech.support@xyz.com'"
        }
Depending on how your actual $USER6$ (password) looks like, you may have to add quotes to $USER6$ when you "use" it in the command (hint: shell special characters).

And by the way, what does /var/log/sendEmail say?
--
D/\N
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Failed to Start Nagios service

Post by Ravikimt »

I have one doubt, We are running Nagios core on two machines with the same configuration. In one machine Nagios is working fine without any issues but in another machine we are facing this issue.

How it can be possible something works on one machine and doesn't work on another machine.? I have verified that both the machines have same configuration file with the same permissions.

Only difference is that we are running Nagios on Ubuntu 16.04 LTS in one machine and another on 18.04 LTS.
danjoh
Posts: 73
Joined: Mon Dec 07, 2015 10:43 am
Location: Zürich, Switzerland
Contact:

Re: Failed to Start Nagios service

Post by danjoh »

Different versions of sendEmail?

Different paths to sendEmail?
Run

Code: Select all

locate sendEmail
and/or

Code: Select all

which sendEmail
on both systems and check for differences.
--
D/\N
Locked