How to add process info (like from top) in cpu alert email?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
mlangkau
Posts: 6
Joined: Mon Jan 07, 2013 10:35 pm

How to add process info (like from top) in cpu alert email?

Post by mlangkau »

Is there a way to add the output from the "top" command to an email alert? We currently use nrpe to monitor Linux systems.

For example, when cpu or load crosses a threshold, I would like to include the output of something like this:

top -cSbn 1 | head -14 | tail -8

...and the resulting output looks like this:

Code: Select all

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
17294 apache    20   0  515m  84m 8768 R 100.0  2.2   4:13.14 /usr/sbin/httpd
29665 nagios    20   0 51656 3168 1036 S  2.0  0.1  17:21.22 /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
31175 nagios    20   0 15164 1188  816 R  2.0  0.0   0:00.01 top -cSbn 1
    1 root      20   0 19364 1028  820 S  0.0  0.0  12797:05 /sbin/init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.01 [kthreadd]
    3 root      RT   0     0    0    0 S  0.0  0.0  19:43.57 [migration/0]
    4 root      20   0     0    0    0 S  0.0  0.0   4:26.39 [ksoftirqd/0]
Thanks
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: How to add process info (like from top) in cpu alert ema

Post by bwallace »

This is not possible, as the only info that one can feasibly have in a notification is data which the plugin itself actually gathered - you can't get it to run top or any other utility and then have the output written to your email. Maybe this doc will assist with your effort to further customize notifications, but understand that it won't assist with what you're specifically asking here.
https://assets.nagios.com/downloads/nag ... iables.pdf

Hope this helps, but let us know if there are any other questions, thanks.
Be sure to check out the Knowledgebase for helpful articles and solutions!
mlangkau
Posts: 6
Joined: Mon Jan 07, 2013 10:35 pm

Re: How to add process info (like from top) in cpu alert ema

Post by mlangkau »

Got it. I wasn't sure if an event handler could be used to get the info, but getting it into the email isn't possible. If I understand correctly, I'll need to clone and edit the plugin to include the additional information we are looking for.

Does anyone know if a cpu/memory stats plugin already exists that provides top process information?

Thanks!
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: How to add process info (like from top) in cpu alert ema

Post by tgriep »

Does this plugin look like what you are looking for?
https://exchange.nagios.org/directory/P ... rs/details
Be sure to check out our Knowledgebase for helpful articles and solutions!
mlangkau
Posts: 6
Joined: Mon Jan 07, 2013 10:35 pm

Re: How to add process info (like from top) in cpu alert ema

Post by mlangkau »

That sounds like a winner - I'll check it out.

Thanks!
mlangkau
Posts: 6
Joined: Mon Jan 07, 2013 10:35 pm

Re: How to add process info (like from top) in cpu alert ema

Post by mlangkau »

Yes, this works. Thanks again!
Locked