<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.zhouba.cz/index.php?action=history&amp;feed=atom&amp;title=ZhoubaWiki%3AIcingaEventHandlerInstallation</id>
	<title>ZhoubaWiki:IcingaEventHandlerInstallation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.zhouba.cz/index.php?action=history&amp;feed=atom&amp;title=ZhoubaWiki%3AIcingaEventHandlerInstallation"/>
	<link rel="alternate" type="text/html" href="https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:IcingaEventHandlerInstallation&amp;action=history"/>
	<updated>2026-04-04T08:15:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:IcingaEventHandlerInstallation&amp;diff=27&amp;oldid=prev</id>
		<title>Garak: Created page with &quot;&lt;!-- Category section --&gt; Category:Zhouba &lt;!-- Contents --&gt; {| align=&quot;right&quot;  | __TOC__  |} '''Introduction to Setting up event handlers triggering on remote servers'''&lt;br...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:IcingaEventHandlerInstallation&amp;diff=27&amp;oldid=prev"/>
		<updated>2021-05-22T16:40:12Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;!-- Category section --&amp;gt; &lt;a href=&quot;/index.php?title=Category:Zhouba&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Zhouba (page does not exist)&quot;&gt;Category:Zhouba&lt;/a&gt; &amp;lt;!-- Contents --&amp;gt; {| align=&amp;quot;right&amp;quot;  | __TOC__  |} &amp;#039;&amp;#039;&amp;#039;Introduction to Setting up event handlers triggering on remote servers&amp;#039;&amp;#039;&amp;#039;&amp;lt;br...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;!-- Category section --&amp;gt;&lt;br /&gt;
[[Category:Zhouba]]&lt;br /&gt;
&amp;lt;!-- Contents --&amp;gt;&lt;br /&gt;
{| align=&amp;quot;right&amp;quot;&lt;br /&gt;
 | __TOC__&lt;br /&gt;
 |}&lt;br /&gt;
'''Introduction to Setting up event handlers triggering on remote servers'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For illustration &amp;lt;code&amp;gt;eh_restart_service&amp;lt;/code&amp;gt; event handler installation is described&lt;br /&gt;
&lt;br /&gt;
==Monitoring server part==&lt;br /&gt;
Having &amp;lt;code&amp;gt;check_remote&amp;lt;/code&amp;gt; set up this way:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define command {&lt;br /&gt;
	command_name check_remote&lt;br /&gt;
	command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p $_HOSTPORT$ -u -c $ARG1$ -t 120&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
simple new service definition row is to be added like this:&lt;br /&gt;
 &amp;lt;tt&amp;gt;# generic response code template&lt;br /&gt;
 define service{&lt;br /&gt;
     name			response-code-template&lt;br /&gt;
     use				generic-service-charted&lt;br /&gt;
     check_interval		0.25&lt;br /&gt;
     retry_interval		0.25&lt;br /&gt;
     max_check_attempts		3&lt;br /&gt;
     flap_detection_enabled	0&lt;br /&gt;
     register			0&lt;br /&gt;
 }&lt;br /&gt;
 # trackers&lt;br /&gt;
 define service{&lt;br /&gt;
     use				response-code-template&lt;br /&gt;
     hostgroup_name		trackers&lt;br /&gt;
     service_description		Check HTTPS success response code&lt;br /&gt;
     check_command		check_https_success_response!S!/&lt;br /&gt;
     &amp;lt;span style=&amp;quot;color: red&amp;quot;&amp;gt;'''event_handler	    check_remote!restart_service_tracker'''&amp;lt;/span&amp;gt;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
Note that &amp;lt;code&amp;gt;max_check_attempts&amp;lt;/code&amp;gt; directive has to be set to have a value of more than &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, ideally at least &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;. It is so because event handlers are executed on soft states only (1/3, 2/3) - to avoid unnecessary notifications.&lt;br /&gt;
&lt;br /&gt;
==Remote server part==&lt;br /&gt;
1. Copy the event handler script (can be in any executable form) the the remote server's plugin directory (typically &amp;lt;code&amp;gt;/usr/lib/nagios/plugins&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
2. Assign it as an NRPE plugin under tha same name as check_nrpe's parameter (in this case &amp;lt;code&amp;gt;restart_service_tracker&amp;lt;/code&amp;gt;) into &amp;lt;code&amp;gt;nrpe.cfg&amp;lt;/code&amp;gt; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
command[restart_service_tracker]=sudo /usr/lib/nagios/plugins/eh_restart_service -s tracker&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Note the usage of sudo prefix - it is so due to the necessity of broader privileges for services restarting.&lt;br /&gt;
&lt;br /&gt;
3. Don't forget to restart the daemon afterwards&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/nagios-nrpe-server restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Add the nagios user privilege to execute nagios plugins using sudo. /etc/sudoers snippet example follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow members of group sudo to execute any command&lt;br /&gt;
%sudo   ALL=(ALL:ALL) NOPASSWD: ALL&lt;br /&gt;
nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Now you can issue test command to verify everything on remote server is set up OK&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/lib/nagios/plugins/check_nrpe -H localhost -c restart_service_tracker&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:This exact event handler outputs 'OK', exits with a code of 0 and writes log entry into &amp;lt;code&amp;gt;/icinga/eh_restart_service.log&amp;lt;/code&amp;gt;. Consult source code of your event handler script to evaluate it works OK;-)&lt;br /&gt;
&lt;br /&gt;
6. If still unsure it works ok, manually stop the service and issue the command of point 5 again. Then see service status and calm down.&lt;/div&gt;</summary>
		<author><name>Garak</name></author>
	</entry>
</feed>