{"id":1257,"date":"2020-04-19T23:31:07","date_gmt":"2020-04-19T23:31:07","guid":{"rendered":"\/blog\/?p=1257"},"modified":"2020-04-20T02:21:11","modified_gmt":"2020-04-20T02:21:11","slug":"nagios-event-handlers","status":"publish","type":"post","link":"\/blog\/index.php\/nagios-event-handlers\/","title":{"rendered":"Nagios Event Handlers"},"content":{"rendered":"<p><a href=\"\/blog\/wp-content\/uploads\/2020\/04\/Restarting-Linux-Services-With-NRPE.pdf\">Restarting-Linux-Services-With-NRPE<\/a><br \/>\nhttps:\/\/assets.nagios.com\/downloads\/nagiosxi\/docs\/Restarting-Linux-Services-With-NRPE.pdf<\/p>\n<p>At each monitored server<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nAdd this line to \/usr\/local\/nagios\/etc\/nrpe.cfg :<br \/>\ncommand[service_restart]=sudo service $ARG1$ restart 2>&#038;1<\/p>\n<p>And give nagios permissions to execute service<br \/>\necho &#8220;nagios ALL = NOPASSWD: `which service`&#8221; > \/etc\/sudoers.d\/nagios<\/p>\n<p>At the Nagios XI server<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n&#8211; Test with<br \/>\n\/usr\/local\/nagios\/libexec\/check_nrpe -H 10.25.13.34 -c service_restart -a apache2<br \/>\n&#8211; add these contents to  \/usr\/local\/nagios\/libexec\/service_restart.bash<br \/>\n#!\/bin\/bash<br \/>\ncase &#8220;$1&#8221; in<br \/>\nOK)<br \/>\n;;<br \/>\nWARNING)<br \/>\n;;<br \/>\nUNKNOWN)<br \/>\n;;<br \/>\nCRITICAL)<br \/>\n\/usr\/local\/nagios\/libexec\/check_nrpe -H &#8220;$2&#8221; -c service_restart -a &#8220;$3&#8221;<br \/>\n;;<br \/>\nesac<br \/>\nexit 0<\/p>\n<p>&#8211; set permissions<br \/>\nchown apache:nagios \/usr\/local\/nagios\/libexec\/service_restart.bash<br \/>\nchmod 775 \/usr\/local\/nagios\/libexec\/service_restart.bash<\/p>\n<p>-test<br \/>\n\/usr\/local\/nagios\/libexec\/service_restart.sh CRITICAL 10.25.13.34 apache2<\/p>\n<p>&#8211; Create a &#8220;command&#8221; in the core config mannager with this command line:<br \/>\n$USER1$\/service_restart.sh $SERVICESTATE$ $HOSTADDRESS$ $_SERVICESERVICE$<br \/>\nAlso select &#8220;misc_command&#8221; from command type<\/p>\n<p>&#8211; Update a service adding the event handler<\/p>\n<p>&#8211; in the misc settings add a &#8220;free variable&#8221;<br \/>\n_SERVICE apache2<\/p>\n<p>Read:<br \/>\nhttps:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/3\/en\/eventhandlers.html#example<br \/>\nhttp:\/\/www.techadre.com\/content\/nagios-event-handler-restart-remote-service<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"2mxbnqJAls\"><p><a href=\"https:\/\/kakoma.ug\/code\/2014\/12\/nagios-event-handlers-nrpe\">Nagios event handlers for NRPE<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"https:\/\/kakoma.ug\/code\/2014\/12\/nagios-event-handlers-nrpe\/embed#?secret=2mxbnqJAls\" data-secret=\"2mxbnqJAls\" width=\"600\" height=\"338\" title=\"&#8220;Nagios event handlers for NRPE&#8221; &#8212; Kakoma.ug\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><br \/>\nhttps:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/3\/en\/objecttricks.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Restarting-Linux-Services-With-NRPE https:\/\/assets.nagios.com\/downloads\/nagiosxi\/docs\/Restarting-Linux-Services-With-NRPE.pdf At each monitored server &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Add this line to \/usr\/local\/nagios\/etc\/nrpe.cfg : command[service_restart]=sudo service $ARG1$ restart 2>&#038;1 And give nagios permissions to execute service echo &#8220;nagios ALL = NOPASSWD: `which service`&#8221; > \/etc\/sudoers.d\/nagios At the Nagios XI server &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8211; Test with \/usr\/local\/nagios\/libexec\/check_nrpe -H 10.25.13.34 -c service_restart -a apache2 &#8211; add these contents to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1257","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1257"}],"version-history":[{"count":7,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1257\/revisions"}],"predecessor-version":[{"id":1265,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1257\/revisions\/1265"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1257"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}