User Tools

Site Tools


userspace:current_opsi_errors
#!/bin/bash
 
# License: GPL
# NO WARRANTY
 
# This script was written to find out which opsi products failed recently.
# opsi-admin returns a list of all products where state is "unknown" and action
# is "none". This script just saves the list and compares it to the list it got
# last time. After that, this script tries to get the cause of the error by
# grep for "fatal error" at the opsi logfile.
 
# You can also start this script by cron and configure cron to mail the output.
 
# If you have any suggestions, questions or comments,
# please put them here: http://forum.opsi.org/wiki/userspace
 
# Copyright User "test", 2013
 
FOLDER=$HOME/ErrorState
ERRORSBEFORE=$FOLDER/unknown-1.txt
ERRORSNOW=$FOLDER/unknown-2.txt
CLIENTLIST=/tmp/list-clients.txt
NEWERRORS=/tmp/new-opsi-errors.txt
NOW=`date +%Y-%m-%d_%H-%M-%S`
 
# First call of this script: There is no list from "before",
# so create an empty list.
if [[ ! -f $ERRORSBEFORE ]]
then    mkdir -p $FOLDER
        echo '[' >  $ERRORSBEFORE
        echo ']' >> $ERRORSBEFORE
fi
 
# Get all packages on clients where state=unknown and action=none. Remove " and , - then sort and save the list.
opsi-admin -d method productOnClient_getIdents '[]' \{\"installationStatus\":\"unknown\",\"actionRequest\":\"none\"\} | sed 's/\"//g;s/,$//g'| sort > $ERRORSNOW
 
# Compare list before and after this check. List "new" errors. 
diff $ERRORSBEFORE $ERRORSNOW| grep '>' | cut -d' ' -f2- > $NEWERRORS
cat $NEWERRORS | cut -f3 -d';' | sort -u > $CLIENTLIST
 
# No new errors since last call. Clean up and exit.
if ! [[ -s $NEWERRORS ]]
then    rm $NEWERRORS
        mv $ERRORSNOW $ERRORSBEFORE
        exit 0
fi
 
# List new errors.
echo -e 'List of products on clients with state:unknown and action:none\n'
cat $NEWERRORS
echo -e '\nList of error messages from logfiles:'
 
# Search for error message of failed product(s).
cd /var/log/opsi/instlog/
for client in `cat $CLIENTLIST`
do if [[ ! -s  $client.log ]]
   then echo "$client: no logfile." 
   else
     # Find all failed packages of one client. Search logfile for error message(s). Then write client
     # and product name before the text of the error message.
     grep $client $NEWERRORS | cut -f1 -d';' | while read product
       do grep -B20 "installed product: $product" $client.log | grep -B1 'fatal' | grep -v 'Error level set to fatal' | grep -v '^--$' | grep -v '\t$' | sed "s/^/$client: $product\t/g"
       done
   fi
done
 
rm $NEWERRORS
mv $ERRORSNOW $ERRORSBEFORE
userspace/current_opsi_errors.txt · Last modified: 2021/08/23 08:37 (external edit)