# ==================================================================== # Title: dni_network.mod # Author: Peter M. Abraham # Dynamic Net, Inc. # 13 Cowpath # Denver, PA 17517 # 1-717-484-1062 # EMail: peter.abraham@dynamicnet.net # URL: http://www.dynamicnet.net/ # Copyright (c) 2012 Dynamic Net, Inc. All rights Reserved. # Date: 02/06/2012 # -------------------------------------------------------------------- # Modifications # 02/07/2012 thanks to Jeffery Kilonsky, use -w with grep per # http://forum.psoft.net/showthread.php?t=31148&p=155639#post155639 # # -------------------------------------------------------------------- # Purpose: A System Integrity Monitor -- S.I.M. -- add on module # to check if a given H-Sphere network card IP address # is online. # # If the IP is offline but present in # /hsphere/local/network/ips then run # /hsphere/shared/scripts/setup-ips.pl # to re-establish the IP adddresses. # # If that works, then restart key services # based on what key services exist on the # machine # -------------------------------------------------------------------- # http://www.rfxn.com/projects/system-integrity-monitor/ # S.I.M. - System Integrity Monitor is written and # maintained by Ryan MacDonald. # # Our copyright is only on this addon module. # # -------------------------------------------------------------------- ## INSTALLATION INSTRUCTIONS # cd /usr/local/sim/modules/system/ # wget -N http://dynamicnet.net/download/rfx/dni_network.mod # chmod 640 dni_network.mod # vi dni_network.mod # REPLACE the IP_CHECK IP address, and save the file ## ## # vi /usr/local/sim/config/mods.control and add the following line under sys.network off # # sys.dni_network on # ## make sure the above sys.dni_network on line is uncommented in /usr/local/sim/config/mods.control # ## Test with "sim -s" # #sim_modv3x #disable nameval=dni_network # # Replace IP below with unique service IP from /hsphere/local/network/ips # It is best if it is a logical service IP other than web (i.e. mysql, dns, etc.) # IP_CHECK='173.193.203.200' # # # ST_NET - check if the IP is online # HSPHERE_NET - check if the IP address that should be online is in /hsphere/local/network/ips which is called by /hsphere/shared/scripts/setup-ips.pl # ST_NET=`/sbin/ifconfig | /bin/grep inet | /usr/bin/cut -d : -f 2 | /usr/bin/cut -d \ -f 1 | /bin/grep -w $IP_CHECK` HSPHERE_NET=`/bin/grep -w $IP_CHECK /hsphere/local/network/ips | /usr/bin/cut -f 1` sanity_path $INSTALL_PATH/internals/stat/$nameval.stat 3 if [ "$ST_NET" != $IP_CHECK ]; then echo " $IP_CHECK offline" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK off line" 1 track_event $nameval ALERT=1 # # If the IP is off line but not in /hsphere/local/network/ips then running /hsphere/shared/scripts/setup-ips.pl will accomplish nothing if [ "$HSPHERE_NET" != $IP_CHECK ]; then echo " $IP_CHECK offline and not in /hsphere/local/network/ips" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK off line and not in /hsphere/local/network/ips" 1 else echo " $IP_CHECK offline and running /hsphere/shared/scripts/setup-ips.pl" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK off line and running /hsphere/shared/scripts/setup-ips.pl" 1 `/hsphere/shared/scripts/setup-ips.pl` # Now double check that running /hsphere/shared/scripts/setup-ips.pl brought the IP address back online CHECK_NET=`/sbin/ifconfig | /bin/grep inet | /usr/bin/cut -d : -f 2 | /usr/bin/cut -d \ -f 1 | /bin/grep -w $IP_CHECK` if [ "$CHECK_NET" != $IP_CHECK ]; then echo " $IP_CHECK offline and /hsphere/shared/scripts/setup-ips.pl did not fix" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK off line and /hsphere/shared/scripts/setup-ips.pl did not fix" 1 else echo " $IP_CHECK ONLINE FIXED BY running /hsphere/shared/scripts/setup-ips.pl" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK ONLINE FIXED BY running /hsphere/shared/scripts/setup-ips.pl" 1 # Now restart services that may be on the machine based on the service existance in the /etc/rc.d/init.d directory if [ -f /etc/rc.d/init.d/named ]; then `/etc/rc.d/init.d/named restart >/dev/null` echo " $IP_CHECK - named restarted" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK - named restarted" 1 fi if [ -f /etc/rc.d/init.d/mysql ]; then `/etc/rc.d/init.d/mysql restart >/dev/null` echo " $IP_CHECK - mysql restarted" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK - mysql restarted" 1 fi if [ -f /etc/rc.d/init.d/postgresql ]; then `/etc/rc.d/init.d/postgresql restart >/dev/null` echo " $IP_CHECK - postgresql restarted" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK - postgresql restarted" 1 fi if [ -f /etc/rc.d/init.d/qmaild ]; then `/etc/rc.d/init.d/qmaild restart >/dev/null` `/etc/rc.d/init.d/courier-imapd restart >/dev/null` `/etc/rc.d/init.d/courier-imapd-ssl restart >/dev/null` echo " $IP_CHECK - mail services restarted" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK - mail services restarted" 1 fi if [ -f /etc/rc.d/init.d/httpd ]; then `/etc/rc.d/init.d/httpd restart >/dev/null` echo " $IP_CHECK - httpd restarted" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK - httpd restarted" 1 fi fi fi else echo " $IP_CHECK online" >> $INSTALL_PATH/internals/stat/$nameval.stat echo_out "$IP_CHECK is online" 1 fi ### EOF