Page 1 of 2

Use Nagios and Xen

Posted: Mon Jul 18, 2016 9:33 am
by hack3rcon
Hello.
I installed Nagios 4 on my Dom0 and it can show something about my Dom0 but how can I monitor my Xen and DomU with Nagios? I google it and found below link but how can I use these scripts? Must I copy them somewhere?

https://exchange.nagios.org/directory/P ... nments/Xen

Please advice me.

Thank you.

Re: Use Nagios and Xen

Posted: Mon Jul 18, 2016 10:50 am
by rkennedy
All of the different plugins work a bit differently. Some will need to run on the local machine, while others will pull information using SSH or NRPE.

https://exchange.nagios.org/directory/P ... sh/details for example, could be used in conjunction with NRPE, or check_by_ssh. This one has a comment with instructions on what needs to be done, to use check_by_ssh. You would need to upload it to the local

The same goes with this plugin for example, which would need to run locally https://exchange.nagios.org/directory/P ... en/details. SSH / NRPE is just used as a way to relay information back to the Nagios host.

This document is written for XI, but the same principal applies when creating SSH keys. It might benefit you depending on the route you choose to go. https://assets.nagios.com/downloads/nag ... ng_SSH.pdf

If you decide to use NRPE, take a look at this document - https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Re: Use Nagios and Xen

Posted: Tue Jul 19, 2016 12:44 am
by hack3rcon
Excuse me, I installed Nagios via "http://www.tecmint.com/install-nagios-in-linux/" and installed it on my localhost (Dom0) and as I understand it monitor my localhost by default, But I like to monitor Xen deeply, For example, Is my Xen work correctly, Monitor my DomU and...
Can you tell me how can I use Nagios plugins step by step? For monitor DomU must I write a config file?

Thank you.

Re: Use Nagios and Xen

Posted: Tue Jul 19, 2016 1:50 pm
by rkennedy
Your DomU host should already have a configuration file built, called localhost.cfg. Take a look at your configuration folder and you'll see it there. (usually around /usr/local/nagios/etc/ - might have to go another folder deep)

I don't have a step by step available, as I mentioned all plugins are different. If you want to use check_by_ssh in conjunction with your Xen server, then follow the instructions in the comment on this page - https://exchange.nagios.org/directory/P ... sh/details
the plugin works perfectly when used on local machine. In order to use it with check_by_ssh you need to do following modifications:

On the monitored host:
in /etc/sudoers add:

Defaults:nagios !requirettl
nagios ALL=(ALL) NOPASSWD: /check_xen *

edit the script:

in the line RUNNING=$(sudo /usr/sbin/xm list | awk '!/[DN]/ {print $1 }' | awk '$1=$1' OFS=", " RS= )
remove sudo:
RUNNING=$( /usr/sbin/xm list | awk '!/[DN]/ {print $1 }' | awk '$1=$1' OFS=", " RS= )

On the Nagios host:
add command:
define command{
command_name ssh_xen
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C 'sudo /check_xen -w $ARG1$ -c $ARG2$'
}
Then, yes, you would need to create a new configuration file for your Xen machine. Let's call it 'xen.cfg', located in /usr/local/nagios/etc/xen.cfg -

Code: Select all

define host {
        host_name                       xen
        use                             linux-server
        alias                           localhost
        address                         1.2.3.4
        register                        1
        }

define service {
        host_name                       xen
        service_description             Xen Current VMs
        use                             local-service
        check_command                   ssh_xen!5!10
        register                        1
        }
Now, modify your /usr/local/nagios/etc/nagios.cfg and add the following line to add your xen.cfg file in to the Nagios sytem -

Code: Select all

cfg_file=/usr/local/nagios/etc/xen.cfg
Run service nagios restart, and you should now see a host and a service for that check.

Make sure you follow this document to setup the SSH keys - https://assets.nagios.com/downloads/nag ... ng_SSH.pdf

Re: Use Nagios and Xen

Posted: Wed Jul 20, 2016 7:03 am
by hack3rcon
I removed "sudo" and replaced "xm" with "xl" Then put "check_xen" in "/usr/local/nagios/libexec/" and use "chmod +x check_xen", then "/etc/sudoers" add below line :
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/*

then Open localhost from "/usr/local/nagios/etc/objects" and below lines :

define command{
command_name ssh_xen
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C 'sudo /check_xen -w $ARG1$ -c $ARG2$'
}

Then create "/usr/local/nagios/etc/xen.cfg" as you said and add "cfg_file=/usr/local/nagios/etc/xen.cfg" to "nagios.cfg" too.

Am I on a right way?

Then use "service nagios restart" but I got below error :

Restarting nagios (via systemctl): Job for nagios.service failed because a timeout was exceeded. See "systemctl status nagios.service" and "journalctl -xe" for details.
[FAILED]
And when I use "journalctl -xe" :

Code: Select all

Jul 20 07:58:25 localhost.localdomain audit[14342]: CRYPTO_KEY_USER pid=14342 uid=0 auid=4294967295 ses=4294967295 su
Jul 20 07:58:25 localhost.localdomain audit[14342]: CRYPTO_KEY_USER pid=14342 uid=0 auid=4294967295 ses=4294967295 su
Jul 20 07:58:25 localhost.localdomain audit[14342]: CRYPTO_KEY_USER pid=14342 uid=0 auid=4294967295 ses=4294967295 su
Jul 20 07:58:25 localhost.localdomain audit[14342]: CRYPTO_KEY_USER pid=14342 uid=0 auid=4294967295 ses=4294967295 su
Jul 20 07:58:25 localhost.localdomain audit[14342]: USER_LOGIN pid=14342 uid=0 auid=4294967295 ses=4294967295 subj=sy
Jul 20 08:00:23 localhost.localdomain systemd[1]: nagios.service: Start operation timed out. Terminating.
Jul 20 08:00:23 localhost.localdomain systemd[1]: Failed to start LSB: start and stop Nagios monitoring server.
-- Subject: Unit nagios.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nagios.service has failed.
-- 
-- The result is failed.
Jul 20 08:00:23 localhost.localdomain audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_
Jul 20 08:00:23 localhost.localdomain systemd[1]: nagios.service: Unit entered failed state.
Jul 20 08:00:23 localhost.localdomain systemd[1]: nagios.service: Failed with result 'timeout'.
Jul 20 08:00:23 localhost.localdomain polkitd[846]: Unregistered Authentication Agent for unix-process:14163:26942472
Jul 20 08:01:01 localhost.localdomain CROND[14482]: (root) CMD (run-parts /etc/cron.hourly)
Jul 20 08:01:01 localhost.localdomain run-parts[14485]: (/etc/cron.hourly) starting 0anacron
Jul 20 08:01:01 localhost.localdomain run-parts[14491]: (/etc/cron.hourly) finished 0anacron
Jul 20 08:01:01 localhost.localdomain run-parts[14493]: (/etc/cron.hourly) starting mcelog.cron
Jul 20 08:01:01 localhost.localdomain run-parts[14497]: (/etc/cron.hourly) finished mcelog.cron

Re: Use Nagios and Xen

Posted: Wed Jul 20, 2016 10:21 am
by rkennedy
It looks like you did everything properly, my guess is something little is causing the configuration not to start. Let's try verifying the configuration file, to see where it's erroring out. Please run the following and post the output -

Code: Select all

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Re: Use Nagios and Xen

Posted: Sat Jul 23, 2016 1:44 am
by hack3rcon
I did :

Code: Select all

Nagios Core 4.0.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 10-15-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
	Checked 9 services.
	Checked 2 hosts.
	Checked 1 host groups.
	Checked 0 service groups.
	Checked 1 contacts.
	Checked 1 contact groups.
	Checked 25 commands.
	Checked 5 time periods.
	Checked 0 host escalations.
	Checked 0 service escalations.
Checking for circular paths...
	Checked 2 hosts
	Checked 0 service dependencies
	Checked 0 host dependencies
	Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

Re: Use Nagios and Xen

Posted: Sat Jul 23, 2016 7:18 am
by hack3rcon
How about other steps? Did I they correct?

Re: Use Nagios and Xen

Posted: Sun Jul 24, 2016 11:10 pm
by Box293
Is SELinux enabled on your system ? If it is, try setting it to permissive.

Re: Use Nagios and Xen

Posted: Mon Jul 25, 2016 12:52 am
by hack3rcon
Box293 wrote:Is SELinux enabled on your system ? If it is, try setting it to permissive.
I did :
# setenforce 0

But not matter :(

Code: Select all

[root@localhost libexec]# journalctl -xe
Jul 25 01:54:36 localhost.localdomain audit[24392]: CRED_ACQ pid=24392 uid=0 auid=0 ses=12 subj=system_u:system_r:s
Jul 25 01:54:36 localhost.localdomain audit[24384]: USER_LOGIN pid=24384 uid=0 auid=0 ses=12 subj=system_u:system_r
Jul 25 01:54:36 localhost.localdomain audit[24384]: USER_START pid=24384 uid=0 auid=0 ses=12 subj=system_u:system_r
Jul 25 01:54:36 localhost.localdomain audit[24384]: CRYPTO_KEY_USER pid=24384 uid=0 auid=0 ses=12 subj=system_u:sys
Jul 25 01:54:36 localhost.localdomain audit[24384]: USER_END pid=24384 uid=0 auid=0 ses=12 subj=system_u:system_r:s
Jul 25 01:54:36 localhost.localdomain sshd[24392]: Received disconnect from 172.30.10.14 port 34233:11: disconnecte
Jul 25 01:54:36 localhost.localdomain audit[24384]: USER_LOGOUT pid=24384 uid=0 auid=0 ses=12 subj=system_u:system_
Jul 25 01:54:36 localhost.localdomain sshd[24392]: Disconnected from 172.30.10.14 port 34233
Jul 25 01:54:36 localhost.localdomain audit[24384]: CRYPTO_KEY_USER pid=24384 uid=0 auid=0 ses=12 subj=system_u:sys
Jul 25 01:54:36 localhost.localdomain audit[24384]: CRYPTO_KEY_USER pid=24384 uid=0 auid=0 ses=12 subj=system_u:sys
Jul 25 01:54:36 localhost.localdomain sshd[24384]: pam_unix(sshd:session): session closed for user root
Jul 25 01:54:36 localhost.localdomain audit[24384]: USER_END pid=24384 uid=0 auid=0 ses=12 subj=system_u:system_r:s
Jul 25 01:54:36 localhost.localdomain audit[24384]: CRED_DISP pid=24384 uid=0 auid=0 ses=12 subj=system_u:system_r:
Jul 25 01:54:36 localhost.localdomain audit[24384]: CRYPTO_KEY_USER pid=24384 uid=0 auid=0 ses=12 subj=system_u:sys
Jul 25 01:54:36 localhost.localdomain audit[24384]: CRYPTO_KEY_USER pid=24384 uid=0 auid=0 ses=12 subj=system_u:sys
Jul 25 01:54:36 localhost.localdomain audit[24384]: CRYPTO_KEY_USER pid=24384 uid=0 auid=0 ses=12 subj=system_u:sys
Jul 25 01:54:36 localhost.localdomain systemd-logind[874]: Removed session 12.
-- Subject: Session 12 has been terminated
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/multiseat
-- 
-- A session with the ID 12 has been terminated.

Code: Select all

[root@localhost libexec]# systemctl status nagios.service
● nagios.service - LSB: start and stop Nagios monitoring server
   Loaded: loaded (/etc/rc.d/init.d/nagios)
   Active: failed (Result: timeout) since Mon 2016-07-25 01:54:28 EDT; 7min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 24099 ExecStart=/etc/rc.d/init.d/nagios start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nagios.service
           ├─1444 /usr/local/nagios/bin/nagios -ud /usr/local/nagios/etc/nagios.cfg
           ├─1448 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1449 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1450 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1451 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1452 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1453 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1454 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1455 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1456 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1457 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1458 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─1459 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           └─1493 /usr/local/nagios/bin/nagios -ud /usr/local/nagios/etc/nagios.cfg

Jul 25 01:49:28 localhost.localdomain systemd[1]: Starting LSB: start and stop Nagios monitoring server...
Jul 25 01:49:28 localhost.localdomain nagios[24099]: nagios (pid 24084 1493 1459 1458 1457 1456 1455 1454 14...g...
Jul 25 01:49:28 localhost.localdomain systemd[1]: nagios.service: PID file /var/nagios/nagios.pid not readab...tory
Jul 25 01:54:28 localhost.localdomain systemd[1]: nagios.service: Start operation timed out. Terminating.
Jul 25 01:54:28 localhost.localdomain systemd[1]: Failed to start LSB: start and stop Nagios monitoring server.
Jul 25 01:54:28 localhost.localdomain systemd[1]: nagios.service: Unit entered failed state.
Jul 25 01:54:28 localhost.localdomain systemd[1]: nagios.service: Failed with result 'timeout'.
Hint: Some lines were ellipsized, use -l to show in full.