# $HeadURL$ $LastChangedRevision$ # vim: set filetype=sh: ############################################################################## # # SET VARIABLES # ############################################################################## rc2truth() { if eval "$1"; then echo true; else echo false; fi; } I_AM_LINUX=$(rc2truth '[ $(uname) = Linux ]') I_AM_SOLARIS=$(rc2truth '[ $(uname) = SunOS ]') I_AM_RPM_BASED=$(rc2truth '[ -f /etc/redhat-release ]') I_AM_DEB_BASED=$(rc2truth '[ -f /etc/debian_version ]') I_AM_WEBSERVER=$(rc2truth '[ -f /etc/apache2/sites-enabled/dione.no-ip.org ]') I_AM_PAACRTSERVER=$(rc2truth '[ -d /var/www/preseed-files/ ]') I_AM_LENNY=$(rc2truth '$I_AM_LINUX && egrep -q "^(5\.0|lenny)" /etc/debian_version') I_AM_SQUEEZE=$(rc2truth '$I_AM_LINUX && egrep -q "^(6\.0|squeeze)" /etc/debian_version') I_AM_MONITORSERVER=$(rc2truth '[ $(uname -n) = fiori -o $(uname -n) = torchio ]') I_AM_SRFSERVER=$(rc2truth '[ $(uname -n) = trennette ]') I_AM_PASTANET=$(rc2truth '[ "X$(dnsdomainname)" = Xpasta.net ]') I_AM_SYSLOGSERVER=$(rc2truth 'ps fax | grep -v grep | grep -q "syslogd -r"') I_AM_PASTANET=$(rc2truth '[ "X$(dnsdomainname)" = Xpasta.net ]') I_AM_WELLCONNECTEDSERVER=$(rc2truth '[ "X$(uname -n)" = Xmacaroni ]') ############################################################################## # # OS # ############################################################################## # Unix srf --id=crontabs --apply=true --archive=true --alert=false "head -10000 /var/spool/cron/crontabs/*" srf --id=crontabroot --apply=true --archive=true --alert=true "cat /var/spool/cron/crontabs/root" srf --id=df --apply=true --archive=true --alert=false "df -klP" srf --id=dmesg --apply=true --archive=true --alert=false "dmesg" srf --id=domainname --apply=true --archive=true --alert=true "domainname" srf --id=group --apply=true --archive=true --alert=true "LC_ALL=C sort -t: -k 1 /etc/group" srf --id=hostname --apply=true --archive=true --alert=true "hostname" srf --id=ypwhich --apply=true --archive=true --alert=true "ypwhich | sed -e 's/\\(torchio\\|fiori\\)/torchio-or-fiori/'" srf --id=hosts --apply=true --archive=true --alert=true "sort /etc/hosts" srf --id=ifconfig --apply=true --archive=true --alert=false "/sbin/ifconfig -a" srf --id=route --apply=true --archive=true --alert=true "/sbin/route -n" srf --id=inetd --apply=true --archive=true --alert=true "cat /etc/inetd.conf" srf --id=last --apply=true --archive=true --alert=false "last" srf --id=lastuniq --apply=true --archive=true --alert=true "last | head -n -2 | awk '{ print \$1 }' | sort -u | egrep -v '(suzie|alexis)'" srf --id=lastb --apply=true --archive=true --alert=true "lastb" srf --id=rootfsrw --apply=true --archive=true --alert=true "eval {touch,rm}\\ \$(srf-config srf_state_prefix)/.rootfsrw.\$\$\\;" srf --id=mailq --apply=true --archive=false --alert=true --diff-text="" "mailq | tail -n +10" srf --id=mailq2 --apply=true --archive=true --alert=false "mailq" srf --id=shadow --apply=true --archive=true --alert=true "cut -f1-2 -d: /etc/shadow | LC_ALL=C sort -t: -k 1" # Omit 'uname -v' because the date changes after reboots. srf --id=unamea --apply=true --archive=true --alert=true "uname -snrmo" srf --id=uptime --apply=true --archive=true --alert=false "uptime" srf --id=who --apply=true --archive=true --alert=false "who" srf --id=ps --apply=true --archive=true --alert=false "ps -efl | sort -b -k 4n" srf --id=nsswitchconf --apply=true --archive=true --alert=true "cat /etc/nsswitch.conf" srf --id=passwd --apply=true --archive=true --alert=true "LC_ALL=C sort -t: -k 1 /etc/passwd" srf --id=path --apply=true --archive=true --alert=true "sh -c 'echo \$PATH'" srf --id=rclocal --apply=true --archive=true --alert=true "cat /etc/rc.local" srf --id=resolvconf --apply=true --archive=true --alert=true "cat /etc/resolv.conf" srf --id=zpoolstatus --apply=true --archive=true --alert=true "/sbin/zpool status" srf --id=sshdconfig --apply=true --archive=true --alert=true "egrep '^[ \t]*(PermitRootLogin|StrictModes|RSAAuthentication|PubkeyAuthentication|IgnoreRhosts|RhostsRSAAuthentication|HostbasedAuthentication|ChallengeResponseAuthentication|PasswordAuthentication|X11Forwarding|PermitEmptyPasswords)' /etc/ssh/sshd_config" # Monitor /etc for changes, but ignore mtab (the automounter means it changes often). srf --id=etcfad --apply=true --archive=true --alert=true --diff-cmd=faddiff "find /etc | egrep -v '^/etc/((mtab|(lvm/(archive|backup)|bind)/.*)|amanda/.*/(curinfo/.*|index/.*|amdump\.[0-9][0-9]*))\$' | mkfad" # The '\\2' is the the five-minute average load. # Solaris srf --id=dfstab --apply=$I_AM_SOLARIS --archive=true --alert=true "cat /etc/dfstab" srf --id=mdcf2 --apply=$I_AM_SOLARIS --archive=true --alert=true "cat /etc/lvm/md.cf" srf --id=mdcf --apply=$I_AM_SOLARIS --archive=true --alert=true "cat /etc/opt/SUNWmd/md.cf" srf --id=metadb --apply=$I_AM_SOLARIS --archive=true --alert=true "metadb" srf --id=metastat --apply=$I_AM_SOLARIS --archive=true --alert=true "metastat" srf --id=eeprom --apply=$I_AM_SOLARIS --archive=true --alert=true "eeprom" srf --id=mount --apply=$I_AM_SOLARIS --archive=true --alert=true "mount -p" srf --id=ntpconf --apply=$I_AM_SOLARIS --archive=true --alert=true "cat /etc/inet/ntp.conf" srf --id=pkginfo --apply=$I_AM_SOLARIS --archive=true --alert=true "pkginfo" srf --id=prtconf --apply=$I_AM_SOLARIS --archive=true --alert=true "prtconf -v" srf --id=prtdiag --apply=$I_AM_SOLARIS --archive=true --alert=true "/usr/platform/sun4u/sbin/prtdiag -v" srf --id=prtvtoc --apply=$I_AM_SOLARIS --archive=true --alert=true "prtvtoc /dev/rdsk/*s2" srf --id=vfstab --apply=$I_AM_SOLARIS --archive=true --alert=true "cat /etc/vfstab" srf --id=showrev --apply=$I_AM_SOLARIS --archive=true --alert=true "showrev -p" srf --id=release --apply=$I_AM_SOLARIS --archive=true --alert=true "cat /etc/release" srf --id=ptree --apply=$I_AM_SOLARIS --archive=true --alert=true "ptree" srf --id=inetdsol --apply=$I_AM_SOLARIS --archive=true --alert=true "cat /etc/inet/inetd.conf" # Linux srf --id=netstat --apply=$I_AM_LINUX --archive=true --alert=false "netstat -plutn" # Don't cat mdstat directly, 'cos order of MDs is not consistent (Judith's machine for example). srf --id=mdstat --apply=$I_AM_LINUX --archive=true --alert=true 'perl -0777 -e "\$_=<>; while (/.*?^(md(\\d+)(.*?\\n.*?\\n))(.*)/ms) { \$x[\$2]=\$1; \$_=\$4; } print join(\"\", sort @x);" /proc/mdstat' srf --id=cmdline --apply=$I_AM_LINUX --archive=true --alert=true "cat /proc/cmdline" srf --id=pvdisplay --apply=$I_AM_LINUX --archive=true --alert=true "/sbin/pvdisplay" srf --id=vgdisplay --apply=$I_AM_LINUX --archive=true --alert=true "/sbin/vgdisplay" srf --id=ntpconf --apply=$I_AM_LINUX --archive=true --alert=true "cat /etc/ntp.conf" srf --id=lvdisplay --apply=$I_AM_LINUX --archive=true --alert=true "/sbin/lvdisplay" srf --id=pvs --apply=$I_AM_LINUX --archive=true --alert=true "/sbin/pvs" srf --id=vgs --apply=$I_AM_LINUX --archive=true --alert=true "/sbin/vgs" srf --id=lvs --apply=$I_AM_LINUX --archive=true --alert=true --diff-opts=-b "/sbin/lvs" srf --id=iscsi --apply=$I_AM_LINUX --archive=true --alert=true "cat /proc/net/iet/volume" srf --id=exports --apply=$I_AM_LINUX --archive=true --alert=true "cat /etc/exports" srf --id=fstab --apply=$I_AM_LINUX --archive=true --alert=true "cat /etc/fstab" srf --id=pstree --apply=$I_AM_LINUX --archive=true --alert=false "pstree -halp" srf --id=xinetd --apply=$I_AM_LINUX --archive=true --alert=true "cat /etc/xinetd.conf" srf --id=lsmod --apply=$I_AM_LINUX --archive=true --alert=false "lsmod | awk '{ print \$1 }' | sort" # This is 'virsh list' with trailing blank line (which screws up sort) removed, time-variant # ID column removed, time-variant idle or running merged, and header lines omitted from sort. srf --id=virshlistall --apply=$I_AM_LINUX --archive=true --alert=true 'virsh list --all | sed -e "\$d" -e "s/^....//" -e "s/\\(idle\\|running\\|no state\\)/idle-or-running-or-no-state/" | { read L1; read L2; echo -e "$L1\\n$L2"; sort; }' srf --id=virshpoollistall --apply=$I_AM_LINUX --archive=true --alert=true 'virsh pool-list --all | sed -e "\$d" | { read L1; read L2; echo -e "$L1\\n$L2"; sort; }' srf --id=virshdumpxml --apply=$I_AM_LINUX --archive=true --alert=false 'for H in $(virsh list --all | sed -e 1,3d | awk "{ print \$2 }" | xargs echo); do echo "=== $H ==="; echo; virsh dumpxml $H; done' srf --id=virshpooldumpxml --apply=$I_AM_LINUX --archive=true --alert=false 'for P in $(virsh pool-list --all | sed -e 1,2d | awk "{ print \$1 }" | xargs echo); do echo "=== $P ==="; echo; virsh pool-dumpxml $P; done' srf --id=mdadm --apply=$I_AM_LINUX --archive=true --alert=true "cat /etc/mdadm/mdadm.conf" # Disable CPU ID retrieval 'cos it gives inconsistently ordered output on both VMs and PMs. # Also note that column width depends on cell contents (e.g. inserting a USB drive can make # every row longer) so we need '-b' option to diff. srf --id=lshw --apply=$I_AM_LINUX --archive=true --alert=true --diff-opts=-b "lshw -quiet -short -disable cpuid" srf --id=lsusb --apply=$I_AM_LINUX --archive=true --alert=true "lsusb" srf --id=lspci --apply=$I_AM_LINUX --archive=true --alert=true "lspci" srf --id=drbd --apply=$I_AM_LINUX --archive=true --alert=true "/usr/sbin/drbd-overview | sed 's/^....//' | sort" # Redhat-based Linux srf --id=raidtab --apply=$I_AM_RPM_BASED --archive=true --alert=true "cat /etc/raidtab" srf --id=release --apply=$I_AM_RPM_BASED --archive=true --alert=true "cat /etc/redhat-release" srf --id=rpmqa --apply=$I_AM_RPM_BASED --archive=true --alert=true "rpm -qa" # Debian-based Linux srf --id=release --apply=$I_AM_DEB_BASED --archive=true --alert=true "cat /etc/debian_version" srf --id=autoremove --apply=$I_AM_DEB_BASED --archive=true --alert=true "apt-get --purge autoremove" # 'dpkg -l' column widths are adjusted to widest name/version to be displayed. This means # deleted the package with the longest version number will affect *all* lines, which makes # detecting *real* changes difficult. Hence string stripping. srf --id=dpkgl --apply=$I_AM_DEB_BASED --archive=true --alert=false "dpkg -l | sed '1,5d' | sed 's/ */ /g'" srf --id=etcdpkgoldnew --apply=$I_AM_DEB_BASED --archive=false --alert=true --diff-text="" "find /etc -name '*.dpkg-*'" # Debian/lenny-based Linux srf --id=ethtool --apply=$I_AM_LENNY --archive=true --alert=true "/usr/sbin/ethtool eth0" # Debian/squeeze-based Linux srf --id=ethtool --apply=$I_AM_SQUEEZE --archive=true --alert=true "/sbin/ethtool eth0" ############################################################################## # # DOMAIN-SPECIFIC # ############################################################################## # keep root's home clean srf --id=rootshomedir --apply=$I_AM_PASTANET --archive=true --alert=true "ls -1a /root | LC_ALL=C sort" srf --id=rootdir --apply=$I_AM_PASTANET --archive=true --alert=true "ls -1a / | LC_ALL=C sort" ############################################################################## # # HOST-SPECIFIC # ############################################################################## # Monitor services (it doesn't really matter which machine does this, but # there is no point in more than one machine doing it) srf --id=dione --apply=$I_AM_WEBSERVER --archive=true --alert=true "wget --quiet --header=\"Host: dione.no-ip.org\" -O - http://dione.no-ip.org/debian/ | LANG=C html2text -width 100 -style compact | col -b" srf --id=habgood --apply=$I_AM_WEBSERVER --archive=true --alert=true "wget --quiet --header=\"Host: habgood.no-ip.org\" -O - http://dione.no-ip.org/ | html2text -width 100 -style compact" srf --id=localpublic --apply=$I_AM_WEBSERVER --archive=true --alert=true "wget --quiet --header=\"Host: dione.no-ip.org\" -O - http://dione.no-ip.org/wordpress/ | html2text -width 100 -style compact | col -b" # '--time-style=long-iso' needed to prevent change of output as modification date passes six months srf --id=commentdata --apply=$I_AM_WEBSERVER --archive=true --alert=true "ls -lrtdc --time-style=long-iso /staging/wikis/*/data/pages/*PageCommentData/revisions/* 2>&1 || true" # Monitor hosts (ditto) srf --id=monitor --apply=$I_AM_MONITORSERVER --archive=true --alert=false "nmap -sP -R --system-dns 192.168.1.0/24 | sed -e '1,2d' -e '\$d'" # Since switching to FastCGI, I get very verbose errors from [[SymLink()]] macro if there are sources which don't exist, even if they are not referenced by current versions of pages. srf --id=wikisymlinks2 --apply=$I_AM_WEBSERVER --archive=true --alert=true --diff-text="" "wget --quiet -O - http://dione.no-ip.org/wordpress/cycling/elbe/ | grep PageComment | true" # Look out for pages with missing 'current' (it's okay if that doesn't point to anything, # but the file should exist. I've seen several pages where it doesn't - they had some # manual moves applied and left skeletons. srf --id=paacrt --apply=$I_AM_PAACRTSERVER --archive=true --alert=true "/root/opt/mdi/bin/paa listavails" # Monitor Deutsche Telekom disconnection time srf --id=telecom --apply=$I_AM_SYSLOGSERVER --archive=true --alert=true "grep -h \"PAP authentication success\" /var/log/syslog{.0,} | tail -1" # Monitor DSL connection speed #srf --id=dslspeed --apply=$I_AM_WELLCONNECTEDSERVER --archive=true --alert=false 'echo "$(T=$(/usr/bin/time -f %e wget --output-document=/dev/null --quiet http://speedtest.wdc01.softlayer.com/downloads/test10.zip 2>&1); S=11536384; echo "scale=2; $S/$T/1024" | bc -q) kB/s"' # This is hosted on Alice's server's so is less affected by other influences. See http://vhost2.hansenet.de/ srf --id=dslspeed --apply=$I_AM_WELLCONNECTEDSERVER --archive=true --alert=false 'echo "$(T=$(/usr/bin/time -f %e wget --output-document=/dev/null --quiet http://vhost2.hansenet.de/bundesliga_manager_x.mpeg 2>&1); S=19168352; echo "scale=2; $S/$T/1024" | bc -q) kB/s"' ############################################################################## # # SELF EXAMINATION # ############################################################################## srf --id=srfconf --apply=true --archive=true --alert=true --diff-opts="-bB" "cat $0" # Monitor who this program is running as srf --id=id --apply=true --archive=true --alert=true "id" # Try to spot orphaned hosts's logs srf --id=orphanedhosts --apply=$I_AM_SRFSERVER --archive=true --alert=true --diff-text="" "cd /staging/logs/srf && find * -maxdepth 0 -type d -mtime 1"