Page 1 of 2
quick action item
Posted: Wed Jul 08, 2015 1:07 pm
by btemple
I was wondering if you guys know of a way to run TOP from the Quick Action screen ? I know you can add custom items but I am not sure what script could be run in the background to produce TOP results remotely ?
Re: quick action item
Posted: Wed Jul 08, 2015 2:01 pm
by lmiltchev
Here's one one you can do it. I have a host that I am monitoring via NRPE. I set up the following command on the remote box (client):
and restarted xinetd:
I made sure it works from the command line on the Nagios XI server:
Code: Select all
/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_top
top - 13:53:09 up 1:01, 1 user, load average: 1.17, 1.15, 1.69
Tasks: 177 total, 3 running, 174 sleeping, 0 stopped, 0 zombie
Cpu(s): 13.7%us, 10.0%sy, 0.0%ni, 53.0%id, 22.2%wa, 0.3%hi, 0.8%si, 0.0%st
Mem: 4019476k total, 1057168k used, 2962308k free, 187104k buffers
Swap: 2064380k total, 0k used, 2064380k free, 341756k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1078 root 20 0 34152 14m 3472 R 15.7 0.4 0:07.80 ncpa_posix_list
1833 root 20 0 47864 4752 2704 S 2.0 0.1 0:30.68 fprobe
26350 nagios 20 0 12240 3632 2520 S 2.0 0.1 0:00.01 sendmail
27007 nagios 20 0 2696 1064 784 R 2.0 0.0 0:00.01 top
1 root 20 0 2900 1416 1204 S 0.0 0.0 0:02.30 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.90 migration/0
4 root
I put the command in a bash shell script, called "top.sh" in the "libexec" directory:
Code: Select all
[root@testbox libexec]# pwd
/usr/local/nagios/libexec
[root@testbox libexec]# cat top.sh
#!/bin/bash
/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_top
exit 0
I added the command (script) to the "Actions" component:
Admin->Manage Components->Actions->Edit Settings
example01.PNG
and clicked on "Apply Settings".
Now, when I click on my host under "Home->Host Detail", I can see the "Top" link under "Quick Actions":
example02.PNG
When I click on it, I can see the top output:
example03.PNG
Re: quick action item
Posted: Wed Jul 08, 2015 2:51 pm
by btemple
this look very good thank you !
Re: quick action item
Posted: Wed Jul 08, 2015 3:40 pm
by ssax
Check it out and let us know if you have any questions.
Re: quick action item
Posted: Thu Jul 09, 2015 12:46 pm
by btemple
This is what we are looking for but, we are going to try to use check_by_ssh instead of NRPE if possible
Re: quick action item
Posted: Thu Jul 09, 2015 1:43 pm
by btemple
this is working from command line need to figure out the quick action part...
-------------------------------
su nagios top.sh
------------------------------
top.sh
#!/bin/bash
/usr/local/nagios/libexec/check_by_ssh -H xxxxx -C "top -cSbn 1"
exit 0
Need to figure out how to inject the name of the server from the quick action to the -H .....
Re: quick action item
Posted: Thu Jul 09, 2015 2:40 pm
by ssax
What you could do is edit the quick action and set the command to:
Code: Select all
/usr/local/nagios/libexec/top.sh '%hostaddress%'
Then change the top.sh script to:
Code: Select all
#!/bin/bash
HOST=$1
/usr/local/nagios/libexec/check_nrpe -H $HOST -c check_top
exit 0
Then you should be golden!
Re: quick action item
Posted: Fri Jul 10, 2015 6:27 am
by btemple
This is the last piece, I need to make the quick action run in the context of my nagios account , I think it's running as root
From the launched screen ...
Running: /usr/local/nagios/libexec/top.sh '172.29.10.169'
Remote command execution failed: Could not create directory '/var/www/.ssh'.
Re: quick action item
Posted: Fri Jul 10, 2015 8:52 am
by tgriep
Did you setup password-less login by ssh for that host?
If not, you need to following the instructions below.
https://assets.nagios.com/downloads/nag ... ng_SSH.pdf
For every host you want to use the quick action item, you will need to follow that procedure.
Edit.
I forgot to add that the Quick Action Item runs as apache so the password less login will have to be setup as the apache user.
And the command will have to be edited to use the nagios login like below.
Code: Select all
/usr/local/nagios/libexec/check_by_ssh -H xxxxx -C "top -cSbn 1" -l nagios
Re: quick action item
Posted: Fri Jul 10, 2015 9:26 am
by btemple
Ok is there anyway to make the quick launch use the "nagios" account instead of "apache" ?