{"id":14,"date":"2014-01-20T13:39:36","date_gmt":"2014-01-20T12:39:36","guid":{"rendered":"http:\/\/luca.lovalvo.net\/1_luca_lo_valvo\/archive\/12545_phpwatch_up_notification.html"},"modified":"2022-11-04T15:34:08","modified_gmt":"2022-11-04T14:34:08","slug":"phpwatch-up-notification","status":"publish","type":"post","link":"https:\/\/luca.lovalvo.ch\/blog\/phpwatch-up-notification\/","title":{"rendered":"phpWatch UP notification"},"content":{"rendered":"<div><a href=\"http:\/\/phpwatch.net\/\" target=\"_blank\" rel=\"noopener\">phpWatch<\/a>&nbsp;est un petit outil &eacute;crit en PHP permettant de faire du monitoring de site web et\/ou de port.<\/div>\n<div><\/div>\n<div>Il n&#39;a pas la pr&eacute;tention d&#39;&ecirc;tre aussi puissant qu&#39;un&nbsp;<a href=\"http:\/\/www.nagios.org\/\" target=\"_blank\" rel=\"noopener\">Nagios<\/a>&nbsp;mais se r&eacute;v&egrave;le tr&egrave;s pratique pour monitorer de petite infra \/ appli \/ outil, comme un NAS &agrave; la maison, un routeur, son site perso, son intranet, etc&#8230;<\/div>\n<div><\/div>\n<div>Bien que phpWatch fonctionne tr&egrave;s bien pour d&eacute;clancher des alertes de downtime, il lui manque une petite fonction de base&#8230; celle de d&eacute;clancher une alerte lors d&#39;un retour &agrave; la normal (uptime).<\/div>\n<p>Pour r&eacute;soudre ce petit manque, rien de plus simple :<\/p>\n<p><strong>Dans src\/Monitor.php<\/strong><br \/>On va passer un &quot;status&quot; (DOWN\/UP) pour modifier le message de notification.<br \/>Par d&eacute;faut, on passera le status &quot;DOWN&quot;.<\/p>\n<p><u>Ligne 167<\/u> :&nbsp;&nbsp;public function sendNotifications();<br \/>On ajoute : <font color=\"#008080\">$status=&quot;DOWN<\/font><font color=\"#3366ff\">&quot;<\/font> &agrave; la fonction &quot;<font color=\"#008080\">sendNotifications()<\/font>&quot;, ce qui donne :<\/p>\n<p><font color=\"#0000ff\">public function sendNotifications($status=&quot;DOWN&quot;);<\/font><\/p>\n<p>&nbsp;<\/p>\n<p><u>Ligne 171<\/u> :&nbsp;doNotify($this);<br \/>On ajoute : <font color=\"#008080\">,$status<\/font> &agrave; la fonction <font color=\"#008080\">doNotify()<\/font>, ce qui donne :&nbsp;<\/p>\n<p><font color=\"#0000ff\">$channel-&gt;doNotify($this,$status);&nbsp;<\/font><\/p>\n<p>&nbsp;<\/p>\n<p><u>Ligne 199<\/u> : On va ajouter une condition, pour le cas d&#39;un UPTIME avec une notification &agrave; 0. Ainsi, lors du changement de status &quot;DOWN =&gt; UP&quot; une notification est d&eacute;clench&eacute;e et ce, qu&#39;une fois.&nbsp;<\/p>\n<p>On va remplacer &nbsp;:&nbsp;<br \/><font color=\"#008000\">$this-&gt;status = STATUS_ONLINE;<br \/>$this-&gt;fail_count = 0;<br \/>$this-&gt;send_notifications = true;&nbsp;<\/font><\/p>\n<p>Par :<\/p>\n<p><font color=\"#0000ff\">$this-&gt;status = STATUS_ONLINE;<span class=\"Apple-tab-span\" style=\"white-space: pre\">\t\t\t\t\t<\/span><\/font><\/p>\n<p><font color=\"#0000ff\">&nbsp; if($this-&gt;status == &quot;1&quot; &amp;&amp; $this-&gt;send_notifications == &quot;0&quot;)<br \/>&nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp;\/\/on envoie un UP<br \/>&nbsp; &nbsp; &nbsp; &nbsp;$this-&gt;sendNotifications(&quot;UP&quot;);<br \/>&nbsp; &nbsp; }<\/font><\/p>\n<p><font color=\"#0000ff\">$this-&gt;fail_count = 0;<br \/>$this-&gt;send_notifications = true;&nbsp;<\/font><\/p>\n<p><u>ligne ~ 223<\/u> : On ajoute le &quot;<font color=\"#008000\">DOWN<\/font>&quot; &agrave; la fonction &quot;<font color=\"#008000\">sendNotifications()<\/font>&quot; ce qui donne :<\/p>\n<p><font color=\"#0000ff\">$this-&gt;sendNotifications(&quot;DOWN&quot;);<\/font><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Dans src\/Channel.php :&nbsp;<\/strong><\/p>\n<p><u>Ligne 89<\/u> : &nbsp;Ajout de la variable &quot;<font color=\"#008000\">$status=&quot;DOWN&quot;<\/font>&quot;<\/p>\n<p><font color=\"#0000ff\">public abstract function doNotify($monitor,$status=&quot;DOWN&quot;);&nbsp;<\/font><\/p>\n<p><strong>Dans src\/channels\/EmailChannel.php et SmsCHannel.php :<\/strong><br \/>Exemple ici avec Smschannel.php<\/p>\n<p><u>ligne 39<\/u> : Ajout de la variable &quot;<font color=\"#008000\">$status=&quot;DOWN&quot;<\/font><\/p>\n<p><font color=\"#0000ff\">public function doNotify($monitor,$status=&quot;DOWN&quot;)<\/font><\/p>\n<p><font color=\"#0000ff\"><\/font>Puis on ajoute avant l&#39;appel de $this-&gt;getMessage($monitor); la variable $status&nbsp;<\/p>\n<p>ce qui donne :<\/p>\n<p><font color=\"#0000ff\">$status.&quot; : &quot;.$this-&gt;getMessage($monitor);&nbsp;<\/font><\/p>\n<p><em>A faire &eacute;galement dans&nbsp;EmailChannel.php&nbsp;<\/em><\/p>\n<p>Le message sera ainsi compos&eacute; de : <br \/><font color=\"#008000\">UP\/DOWN : Message configur&eacute;<\/font> dans les contacts notification channels de votre phpWatch.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>phpWatch&nbsp;est un petit outil &eacute;crit en PHP permettant de faire du monitoring de site web et\/ou de port. Il n&#39;a pas la pr&eacute;tention d&#39;&ecirc;tre aussi puissant qu&#39;un&nbsp;Nagios&nbsp;mais se r&eacute;v&egrave;le tr&egrave;s pratique pour monitorer de petite infra \/ appli \/ outil, comme un NAS &agrave; la maison, un routeur, son site perso, son intranet, etc&#8230; Bien [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-programmation"],"_links":{"self":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":1,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":203,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions\/203"}],"wp:attachment":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}