quick action item

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
btemple
Posts: 183
Joined: Fri Nov 08, 2013 9:30 am

quick action item

Post 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 ?
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: quick action item

Post 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):

Code: Select all

command[check_top]=top -b -n 1
and restarted xinetd:

Code: Select all

service xinetd restart
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
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
btemple
Posts: 183
Joined: Fri Nov 08, 2013 9:30 am

Re: quick action item

Post by btemple »

this look very good thank you !
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: quick action item

Post by ssax »

Check it out and let us know if you have any questions.
btemple
Posts: 183
Joined: Fri Nov 08, 2013 9:30 am

Re: quick action item

Post 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
btemple
Posts: 183
Joined: Fri Nov 08, 2013 9:30 am

Re: quick action item

Post 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 .....
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: quick action item

Post 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!
btemple
Posts: 183
Joined: Fri Nov 08, 2013 9:30 am

Re: quick action item

Post 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'.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: quick action item

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
btemple
Posts: 183
Joined: Fri Nov 08, 2013 9:30 am

Re: quick action item

Post by btemple »

Ok is there anyway to make the quick launch use the "nagios" account instead of "apache" ?
Locked