Nagios: Linux binaries check (a weekly diff) 

#!/bin/bash

# Nagios check
# check name: sec_file_integrity-etc
# uses: ssh and private key to check the server
# log: logs the result using system log

# script args
# $0 - full path to command (default system)
# $1 - user parameter (host to check)
# $2 - user parameter (none)

# SSH credentials
SSH_HOST_TO_CHECK=$1
SSH_USERNAME="xxx"
SSH_PRIVATE_KEY="/home/xxx/.ssh/id_rsa.plain"
SYSLOG_FACILITY="user"
SYSLOG_SEVERITY="info"

# nagios check result states (default)
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

# check pid, run date, name of the check, output to file
MY_PID=$$

# date triggers the interval between the checks (weekly check this time)
#DATE=$( date +%Y%m%d%H%M%S )
DATE=$( date +%Y%W )
DATE_HIST=$( date +%Y%W --date="1 week ago" )

SCRIPT_NAME=`basename $0`
CHECK_RESULT="/tmp/$MY_PID.tmp"
CHECK_RESULT_FILTERED="/tmp/$MY_PID.filtered.tmp"

> $CHECK_RESULT
chown nagios.nagios $CHECK_RESULT

#######################
# check id the ssh command proceeded
function ssh_reachable {
# if host is not reachable exit with STATE_UNKNOWN
if [ $? -ne 0 ]; then
echo "UNKNOWN: host is not reachable"
rm $CHECK_RESULT
exit $STATE_UNKNOWN
fi
}

#######################
# test for parameter
if [ ! $1 ]; then
echo "please state server to check"
exit
fi

#######################
# the actual check body

DATABASE="/usr/local/nagios/hostdb/etc/"
EXECUTABLES="scan.executables"

ssh_reachable

# get the previous database results
EXECUTABLES_HIST=${DATABASE}${SSH_HOST_TO_CHECK}-${DATE_HIST}-${EXECUTABLES}

# check if the historical data exists
if test -f ${DATABASE}${SSH_HOST_TO_CHECK}-${DATE_HIST}-${EXECUTABLES}; then
EXECUTABLES_HIST=${DATABASE}${SSH_HOST_TO_CHECK}-${DATE_HIST}-${EXECUTABLES}
else
EXECUTABLES_HIST="none"
fi

# when the check result file exists for the week, do not run it again
if ! test -f ${DATABASE}${SSH_HOST_TO_CHECK}-${DATE}-${EXECUTABLES}; then
ssh -q -o StrictHostKeyChecking=no -o ConnectTimeout=8 \
-l $SSH_USERNAME -i $SSH_PRIVATE_KEY $SSH_HOST_TO_CHECK '/usr/bin/find /etc/ -type f 2>/dev/null | xargs md5sum' \
1> ${DATABASE}${SSH_HOST_TO_CHECK}-${DATE}-${EXECUTABLES} 2>$CHECK_RESULT
fi

if [ $EXECUTABLES_HIST == "none" ]; then
echo "OK: reinitialize-instance "
exit $STATE_OK
fi

# now to the comparision ( compare new with old )
while read record
do
FILE_MD5SUM=$( echo $record | cut -d" " -f1 )
FILE_NAME=$( echo $record | cut -d" " -f2 )

# get rid of special characters
[ $FILE_NAME == "/usr/bin/[" ] && FILE_NAME="/usr/bin/\["

if [ $( cat $EXECUTABLES_HIST | grep " ${FILE_NAME}\$" 2>/dev/null | wc -l ) -eq 0 ]; then
echo "WARNING: a new executable ( $FILE_NAME )" >> $CHECK_RESULT
else
#echo "OK: in a database ( $FILE_NAME )"
# now check if the file has the same md5sum
MD5SUM=$( cat $EXECUTABLES_HIST | grep " ${FILE_NAME}\$" 2>/dev/null | cut -d" " -f1 )
if [ "$FILE_MD5SUM" != "$MD5SUM" ]; then
echo "CRITICAL: file ( $FILE_NAME ) md5sum is different than md5sum stored a week ago!" >> $CHECK_RESULT
fi
fi
done < ${DATABASE}${SSH_HOST_TO_CHECK}-${DATE}-${EXECUTABLES}

while read line
do
logger -t "$SCRIPT_NAME[$SSH_HOST_TO_CHECK]" -p "$SYSLOG_FACILITY.$SYSLOG_SEVERITY" "$line"
done < $CHECK_RESULT

# evaluation
EXIT_CODE=$STATE_OK

# filter out files and strings we are not interested in (changing frequently)
cat $CHECK_RESULT | \
grep -v "Permission denied" | \
grep -v "/etc/prelink.cache" | \
grep -v " /etc/df.info" > $CHECK_RESULT_FILTERED

# set the exit codes
if [ $( cat $CHECK_RESULT_FILTERED | grep CRITICAL | wc -l ) -ne 0 ]; then
EXIT_CODE=$STATE_CRITICAL
else
if [ $( cat $CHECK_RESULT_FILTERED | grep WARNING | wc -l ) -ne 0 ]; then
EXIT_CODE=$STATE_WARNING
fi
fi

[ $EXIT_CODE -eq 0 ] && echo "OK: consistency achieved"
cat $CHECK_RESULT_FILTERED | sort

rm $CHECK_RESULT
rm $CHECK_RESULT_FILTERED

exit $EXIT_CODE



[ add comment ] ( 11 views )   |  [ 0 trackbacks ]   |  permalink
Check SAN Switch Health  
This plugin checks sensors (psu, temperature, fans et al) and overall health of SAN switches that understand the Fibre Alliance MIB. There is a long list of companies behind that MIB; I have tested the script with switches from Brocade and Qlogic.This plugin checks sensors (psu, temperature, fans et al) and overall health of SAN switches that understand the Fibre Alliance MIB. There is a long list of companies behind that MIB; I have tested the script with switches from Brocade and Qlogic.


http://exchange.nagios.org/directory/Pl ... th/details

[ add comment ] ( 8 views )   |  [ 0 trackbacks ]   |  permalink
Jean Michel Jarre - Equinoxe 5; original video 
http://www.youtube.com/watch?v=AO5w30uKISk

http://www.youtube.com/watch?v=3HJ2Q8GQ ... re=related

http://www.youtube.com/watch?v=YB1Vg-_2 ... re=related



[ add comment ] ( 8 views )   |  [ 0 trackbacks ]   |  permalink
Automate sftp transfer 
sftp -o IdentityFile=/home/user/.ssh/id_rsa user@host:/folder/ <<EOF
mget *
EOF




[ add comment ] ( 8 views )   |  [ 0 trackbacks ]   |  permalink
Adaptec CIM provider freezes on ESX (i) 
http://communities.vmware.com/thread/343231?tstart=0

we have an ESXi 4.1 with the Adaptec CIM provider (the only one available for the 2405 unified controller), using the updated drivers for this controller.

It works basically, but when we poll the provider using remote-arcconf repeatedly (every 30 mins at the moment), the CIM provider stops responding. It will refuse to reply until we stop the polling for a day or two and come back to life magically, just to freeze when some repeated polls are issued.


solution:

echo "01 01 * * * /etc/init.d/sfcbd-watchdog stop; /etc/init.d/sfcbd-watchdog start" >> /var/spool/cron/crontabs/root


then, restart cron:

kill `cat /var/run/crond.pid`




[ add comment ] ( 33 views )   |  [ 0 trackbacks ]   |  permalink
Oracle 11g: error while loading shared libraries: /u01/app/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so 

[root@oracle]# find . -name libclntsh* | xargs chcon -t textrel_shlib_t
[root@oracle]# setenforce 1
[root@oracle]# getenforce
Enforcing


[ add comment ] ( 7 views )   |  [ 0 trackbacks ]   |  permalink
Spacewalk (http://spacewalk.redhat.com/) 
Spacewalk is an open source (GPLv2) Linux systems management solution. It is the upstream community project from which the Red Hat Network Satellite product is derived.



https://fedorahosted.org/spacewalk/wiki/HowToInstall

http://docs.redhat.com/docs/en-US/Red_H ... index.html

http://spacewalk.redhat.com/yum/1.6/RHEL/6/x86_64/



[ add comment ] ( 7 views )   |  [ 0 trackbacks ]   |  permalink
Ilford PAN 400 development times 
http://www.pinhol.com.pl/s&a/artyku ... 100400.pdf

[ 3 comments ] ( 21 views )   |  [ 0 trackbacks ]   |  permalink
Strip off the file name from a path 
echo "/path1/path2/path3/file" | sed -n 's/\(.*\)\/.*$/\1/p'
/path1/path2/path3



verify if the folder is empty or not
# for folder in $( seq -f "%02g" 29 ); do [ "$( ls -A /var/log/clc_archive/2011-09-$folder/)" ] && echo "Syslog data for 2011-09-$folder found" || echo "No data" ; done



[ add comment ] ( 5 views )   |  [ 0 trackbacks ]   |  permalink
DJango 
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

https://www.djangoproject.com/

http://www.djangobook.com/


Database support (PostgreSQL)

http://pkgs.repoforge.org/python-psycopg2/
http://www.cyberciti.biz/faq/psql-fatal ... -for-user/
http://www.postgresql.org/docs/7.4/stat ... ation.html

psql -U postgres -c "CREATE DATABASE mysite" -d template1
psql -U postgres -c "CREATE USER mysite WITH PASSWORD 'mysite'" -d mysite

python manage.py syncdb

Notice
python manage.py runserver 0.0.0.0:8000
python manage.py startapp polls







[ add comment ] ( 6 views )   |  [ 0 trackbacks ]   |  permalink

<<First <Back | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | Next> Last>>