{"id":125,"date":"2016-04-30T22:04:24","date_gmt":"2016-05-01T03:04:24","guid":{"rendered":"https:\/\/servertricks.com\/?p=125"},"modified":"2016-04-30T22:15:54","modified_gmt":"2016-05-01T03:15:54","slug":"setup-network-monitoring","status":"publish","type":"post","link":"https:\/\/servertricks.com\/index.php\/2016\/04\/30\/setup-network-monitoring\/","title":{"rendered":"Setup Network Monitoring"},"content":{"rendered":"<p>You can download the contents of the networkmon.sh script from the downloads section or copy and paste it from here:<\/p>\n<pre>#Update the \"HOSTS\" line with as many domains or IP address you would \r\n#like this script to monitor, separate each with a space.\r\nHOSTS=\"DOMAIN1 DOMAIN2 IPADDR3 IPADDR4\"\r\n# Modify \"COUNT\" to adjust the amount of pings that are sent\r\nCOUNT=1\r\nfor myHost in $HOSTS\r\ndo\r\n  count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')\r\n  if [ $count -eq 0 ]; then\r\n    # If 100% failed email the address below with the message contents of the file \/root\/mail\/networkdown.txt\r\n    echo \"Host : $myHost is down (ping failed) at $(date)\" | ssmtp EMAIL@ADDRESS < \/root\/mail\/networkdown.txt\r\n  fi\r\ndone<\/pre>\n<p>I save the above content in \/scripts\/networkmon.sh, but feel free to save it in a more suitable location for your needs. <\/p>\n<p>Next you need to create the contents of \/root\/mail\/networkdown.txt (again feel free to save this file in a different location and update the file path in the script portion above)<\/p>\n<pre>To: EMAIL@ADDRESS\r\nFrom: sSMTPEMAIL@ADDRESS\r\nSubject: ALERT! Network Down\r\n\r\nThis is a notice that the domain DOMAINNAME did not respond to the 10 minute check in.\r\n\r\nPlease look into the issue!\r\n\r\nThanks\r\nAdmin<\/pre>\n<p>The last step is to make a cron job to run this script every 10 minutes. I use Webmin to make cron jobs, I find it much easier that way. Please view the document \"How to Setup a Cron Job\" if you need further assistance. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can download the contents of the networkmon.sh script from the downloads section or copy and paste it from here: #Update the &#8220;HOSTS&#8221; line with as many domains or IP address you would #like this script to monitor, separate each with a space. HOSTS=&#8221;DOMAIN1 DOMAIN2 IPADDR3 IPADDR4&#8243; # Modify &#8220;COUNT&#8221; to adjust the amount of [&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":[11,10],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-ubuntu","tag-14-04","tag-16-04"],"_links":{"self":[{"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":3,"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":128,"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions\/128"}],"wp:attachment":[{"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/servertricks.com\/index.php\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}