{"id":1169,"date":"2014-05-07T09:11:35","date_gmt":"2014-05-07T07:11:35","guid":{"rendered":"http:\/\/clark.tipistrani.it\/?p=1169"},"modified":"2020-12-17T13:34:56","modified_gmt":"2020-12-17T12:34:56","slug":"check_connection-per-heartbeat","status":"publish","type":"post","link":"http:\/\/clark.tipistrani.it\/?p=1169","title":{"rendered":"check_connection per heartbeat"},"content":{"rendered":"<p>Versione per heartbeat<\/p>\n<p>Per avere la sicurezza che il nodo principale sia su e in caso contrario che il secondario si elegga si deve in qualche modo controllare che la connessione a internet esista.<br \/>\nQuesto sicuramente non \u00e8 il modo pi\u00f9 pulito e migliore per\u00f2 ragionando \u00e8 credo il pi\u00f9 semplice e pratico, in effetti se non si pu\u00f2 navigare \u00e8 ragionevole presumere che la connessione sia interrotta, a questo punto si pu\u00f2 far partire il nodo secondario che dirotter\u00e0 tutto il traffico sulla linea di backup.<br \/>\nlo script di seguito si avvale di un plugin di nagios<\/p>\n<p>#!\/bin\/bash -x<br \/>\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/sbin:\/bin:\/usr\/sbin:\/usr\/bin:\/usr\/lib<\/p>\n<p>### some variables<br \/>\nF_HOST=www.google.com<br \/>\nS_HOST=www.amazon.com<br \/>\nT_HOST=www.corriere.it<br \/>\nCHECK=&#8221;\/usr\/lib\/nagios\/plugins\/check_http -w 5 -c 10&#8243;<br \/>\nHBPIDFILE=`ps -C heartbeat -O pid=`<br \/>\nHEART=&#8217;heartbeat&#8217;<\/p>\n<p>hbalive=0<br \/>\nnetalive=0<\/p>\n<p>if [ -e $HBPIDFILE ]<br \/>\nthen<br \/>\n# runpid=`cat $HBPIDFILE`<br \/>\nrunpid= pgrep heartbeat<br \/>\nfi<br \/>\nif ps ax | grep -v grep | grep $HEART &gt; \/dev\/null<\/p>\n<p>then<br \/>\necho &#8220;heartbeat gira&#8221;<\/p>\n<p>hbalive=1<br \/>\nfi<\/p>\n<p>$CHECK $F_HOST || $CHECK $S_HOST || $CHECK $T_HOST<br \/>\nif [ $? == 0 ]<br \/>\nthen<br \/>\nnetalive=1<br \/>\nfi<br \/>\necho $hbalive $netalive<\/p>\n<p>###se ( hbalive=1 &amp;&amp; netalive=0) -&gt; heartbeat stop<br \/>\n###se ( hbalive=0 &amp;&amp; netalive=1) -&gt; heartbeat start<br \/>\n### se ambedue sono a 0 (rete giu&#8217; heatbeat giu&#8217;) o a 1 (rete su heartbeat su) non bisogna fare nulla<br \/>\nif [ $hbalive -eq $netalive ]<br \/>\nthen<br \/>\necho &#8220;tutto ok&#8221;<br \/>\nexit 0<br \/>\nfi<br \/>\n### se heartbeat e&#8217; giu a seguito di normale down di rete allora deve ripartire se la rete e&#8217; attiva<br \/>\nif [ $hbalive -lt $netalive ]<br \/>\nthen<br \/>\n\/etc\/init.d\/heartbeat start<br \/>\nfi<br \/>\n### se heartbeat e&#8217; su e la rete e&#8217; giu deve fermarsi per fare partire lo slave<br \/>\nif [ $hbalive -gt $netalive ]<br \/>\nthen<br \/>\n\/etc\/init.d\/heartbeat stop<br \/>\nexit 0<br \/>\nfi<\/p>\n<p>Ripeto non sar\u00e0 la cosa pi\u00f9 pulita e stilisticamente perfetta della terra per\u00f2 il suo lavoro lo fa.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Versione per heartbeat Per avere la sicurezza che il nodo principale sia su e in caso contrario che il secondario si elegga si deve in qualche modo controllare che la connessione a internet esista. Questo sicuramente non \u00e8 il modo pi\u00f9 pulito e migliore per\u00f2 ragionando \u00e8 credo il pi\u00f9 semplice e pratico, in effetti [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,8,14,9,7,6],"tags":[],"class_list":["post-1169","post","type-post","status-publish","format-standard","hentry","category-cluster","category-linux","category-networking","category-script","category-sistemi-operativi","category-work"],"_links":{"self":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/1169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1169"}],"version-history":[{"count":4,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/1169\/revisions"}],"predecessor-version":[{"id":1876,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/1169\/revisions\/1876"}],"wp:attachment":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1169"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}