Code: Alles auswählen
* * * * * root bash /var/emu/script/check.reader >/var/log/check.reader.log 2>&1
Code: Alles auswählen
* * * * * root bash /var/emu/script/check.reader >/var/log/check.reader.log 2>&1
Code: Alles auswählen
Apr 17 18:40:01 /USR/SBIN/CRON[3093]: (root) CMD (bash /var/emu/script/check.reader >/var/log/check.reader.log 2>&1)
Da sich hin und wieder mal bei mir einer meiner vier Reader mit "Error" verabschiedet, würde ich auch gerne dieses Script nutzen. In der Regel reicht es nämlich aus den Reader einmal neuzustarten.feissmaik hat geschrieben:Hier eine etwas konfortablere Version von mir vom obigen Code, um rausgeflogene Karten ohne OScam-restart wieder einzubinden:/EDIT: Offensichtlich wurde die Art der Anmeldung für das OScam WebInterface geändert sodass "wget" nicht mehr funktioniert... Deshalb muss das Script angepasst und stattdessen mit curl genutzt werdenSpoilerShowCode: Alles auswählen
#!/bin/bash # #### CONFIG - START ## OScam WebIf with SSL? [1=yes , 0=no] OSssl="0" ## /path/to/oscam.conf? OScfg="/var/etc/oscam.conf" ## Cards to monitor CARD["1"]="mille" CARD["2"]="sky" CARD["3"]="skd" CARD["4"]="skdhd" ## OScam's Logfile? OSlog="/var/log/oscam.log" ## monitoring Error message OSerror="ERROR Phoenix_GetStatus: ioctl error in card detection for %CARDNAME%" ## reporting logfile for this script? OStolog="/var/log/oscam.error" #### CONFIG - END OSip="127.0.0.1" [ "$OSssl" = 1 ] && URL="https://" || URL="http://" # Simple URL encoding proc_url_encode() { out=${1//%/%25}; out=${out//\{/%7B}; out=${out//\}/%7D}; out=${out//|/%7C}; out=${out//\\/%5C}; out=${out//^/%5E}; out=${out//~/%7E}; out=${out//[/%5B}; out=${out//]/%5D}; out=${out//\`/%60}; out=${out//#/%23}; out=${out//>/%3E}; out=${out//\$/%24}; out=${out//&/%26}; out=${out//+/%2B}; out=${out//,/%2C}; out=${out//\//%2F}; out=${out//:/%3A}; out=${out//;/%3B}; out=${out//=/%3B}; out=${out//\?/%3F}; out=${out// /%20}; out=${out//</%3C}; echo $out } proc_parse_cfg() { i=0 while read line; do line=$(echo $line | sed -e 's/ //g') if [[ "$line" =~ ^[^#]*= ]]; then cfg_name[$i]=$(echo $line | cut -d'=' -f 1) cfg_value[$i]=$(echo $line | cut -d'=' -f 2-) ((++i)) fi done < $1 } get_cfg_value() { i=0 for name in ${cfg_name[*]}; do [ "$1" = "$name" ] && echo "${cfg_value[$i]}" && break ((++i)) done } proc_get_infos() { proc_parse_cfg $OScfg WEBPORT=$(get_cfg_value httpport) [ -z "$WEBPORT" ] && "ERROR: WebIf isnt enabled! Abort!" && exit 1 USERNAME=$(get_cfg_value httpuser) if [ ! -z "$USERNAME" ]; then PASSWORD=$(get_cfg_value httppwd) URL="$URL"`proc_url_encode "${USERNAME}"`":"`proc_url_encode "${PASSWORD}"`"@${OSip}:${WEBPORT}" else URL="${URL}$OSip:$WEBPORT" fi } proc_get_infos for card in ${CARD[*]}; do ERRORmsg=${OSerror//%CARDNAME%/$card} founds=`tail -10 $OSlog | grep "$ERRORmsg" | wc -l` if [ $founds -gt 0 ]; then echo "`date +%d-%b-%Y` `date +%H:%M:%S`: $card Card lost" >> $OStolog wget --spider "$URL/readers.html?label=${card}&action=disable" wget --spider "$URL/readers.html?label=${card}&action=enable" fi done exit 0
Vorraussetzung:
apt-get install curl
Code: Alles auswählen
#!/bin/bash # #### CONFIG - START ## OScam WebIf with SSL? [1=yes , 0=no] OSssl="0" ## /path/to/oscam.conf? OScfg="/var/etc/oscam.conf" ## Cards to monitor CARD["1"]="mille" CARD["2"]="sky" CARD["3"]="skd" CARD["4"]="skdhd" ## OScam's Logfile? OSlog="/var/log/oscam.log" ## monitoring Error message OSerror="ERROR Phoenix_GetStatus: ioctl error in card detection for %CARDNAME%" ## reporting logfile for this script? OStolog="/var/log/oscam.error" #### CONFIG - END OSip="127.0.0.1" [ "$OSssl" = 1 ] && URL="https://" || URL="http://" # Simple URL encoding proc_url_encode() { out=${1//%/%25}; out=${out//\{/%7B}; out=${out//\}/%7D}; out=${out//|/%7C}; out=${out//\\/%5C}; out=${out//^/%5E}; out=${out//~/%7E}; out=${out//[/%5B}; out=${out//]/%5D}; out=${out//\`/%60}; out=${out//#/%23}; out=${out//>/%3E}; out=${out//\$/%24}; out=${out//&/%26}; out=${out//+/%2B}; out=${out//,/%2C}; out=${out//\//%2F}; out=${out//:/%3A}; out=${out//;/%3B}; out=${out//=/%3B}; out=${out//\?/%3F}; out=${out// /%20}; out=${out//</%3C}; out=${out//\!/%21}; out=${out//\"/%22}; out=${out//\@/%40}; out=${out//\'/%27}; out=${out//\(/%28}; out=${out//\)/%29}; out=${out//\*/%2A}; out=${out//\-/%2D}; out=${out//\_/%5F}; out=${out//\./%2E}; out=${out//\€/%80}; echo $out } proc_parse_cfg() { i=0 while read line; do line=$(echo $line | sed -e 's/ //g') if [[ "$line" =~ ^[^#]*= ]]; then cfg_name[$i]=$(echo $line | cut -d'=' -f 1) cfg_value[$i]=$(echo $line | cut -d'=' -f 2-) ((++i)) fi done < $1 } get_cfg_value() { i=0 for name in ${cfg_name[*]}; do [ "$1" = "$name" ] && echo "${cfg_value[$i]}" && break ((++i)) done } proc_get_infos() { proc_parse_cfg $OScfg WEBPORT=$(get_cfg_value httpport) [ -z "$WEBPORT" ] && "ERROR: WebIf isnt enabled! Abort!" && exit 1 USERNAME=$(get_cfg_value httpuser) if [ ! -z "$USERNAME" ]; then PASSWORD=$(get_cfg_value httppwd) URL="$URL"`proc_url_encode "${USERNAME}"`":"`proc_url_encode "${PASSWORD}"`"@${OSip}:${WEBPORT}" else URL="${URL}$OSip:$WEBPORT" fi } proc_get_infos for card in ${CARD[*]}; do ERRORmsg=${OSerror//%CARDNAME%/$card} founds=`tail -10 $OSlog | grep "$ERRORmsg" | wc -l` if [ $founds -gt 0 ]; then echo "`date +%d-%b-%Y` `date +%H:%M:%S`: $card Card lost" >> $OStolog curl -s --digest "$URL/readers.html?label=${card}&action=disable" >/dev/null curl -s --digest "$URL/readers.html?label=${card}&action=enable" >/dev/null fi done exit 0
Code: Alles auswählen
apt-get install curl
Code: Alles auswählen
nano /var/emu/script/check.reader
Code: Alles auswählen
#!/bin/bash
#
#### CONFIG - START
## OScam WebIf with SSL? [1=yes , 0=no]
OSssl="0"
## /path/to/oscam.conf?
OScfg="/var/etc/oscam.conf"
## Cards to monitor
CARD["1"]="mille"
CARD["2"]="sky"
CARD["3"]="skd"
CARD["4"]="skdhd"
## OScam's Logfile?
OSlog="/var/log/oscam.log"
## monitoring Error message
OSerror="ERROR Phoenix_GetStatus: ioctl error in card detection for %CARDNAME%"
## reporting logfile for this script?
OStolog="/var/log/oscam.error"
#### CONFIG - END
OSip="127.0.0.1"
[ "$OSssl" = 1 ] && URL="https://" || URL="http://"
# Simple URL encoding
proc_url_encode() {
out=${1//%/%25}; out=${out//\{/%7B}; out=${out//\}/%7D}; out=${out//|/%7C};
out=${out//\\/%5C}; out=${out//^/%5E}; out=${out//~/%7E}; out=${out//[/%5B};
out=${out//]/%5D}; out=${out//\`/%60}; out=${out//#/%23}; out=${out//>/%3E};
out=${out//\$/%24}; out=${out//&/%26}; out=${out//+/%2B}; out=${out//,/%2C};
out=${out//\//%2F}; out=${out//:/%3A}; out=${out//;/%3B}; out=${out//=/%3B};
out=${out//\?/%3F}; out=${out// /%20}; out=${out//</%3C};
out=${out//\!/%21}; out=${out//\"/%22}; out=${out//\@/%40}; out=${out//\'/%27};
out=${out//\(/%28}; out=${out//\)/%29}; out=${out//\*/%2A}; out=${out//\-/%2D};
out=${out//\_/%5F}; out=${out//\./%2E}; out=${out//\€/%80};
echo $out
}
proc_parse_cfg() {
i=0
while read line; do
line=$(echo $line | sed -e 's/ //g')
if [[ "$line" =~ ^[^#]*= ]]; then
cfg_name[$i]=$(echo $line | cut -d'=' -f 1)
cfg_value[$i]=$(echo $line | cut -d'=' -f 2-)
((++i))
fi
done < $1
}
get_cfg_value() {
i=0
for name in ${cfg_name[*]}; do
[ "$1" = "$name" ] && echo "${cfg_value[$i]}" && break
((++i))
done
}
proc_get_infos() {
proc_parse_cfg $OScfg
WEBPORT=$(get_cfg_value httpport)
[ -z "$WEBPORT" ] && "ERROR: WebIf isnt enabled! Abort!" && exit 1
USERNAME=$(get_cfg_value httpuser)
if [ ! -z "$USERNAME" ]; then
PASSWORD=$(get_cfg_value httppwd)
URL="$URL"`proc_url_encode "${USERNAME}"`":"`proc_url_encode "${PASSWORD}"`"@${OSip}:${WEBPORT}"
else
URL="${URL}$OSip:$WEBPORT"
fi
}
proc_get_infos
for card in ${CARD[*]}; do
ERRORmsg=${OSerror//%CARDNAME%/$card}
founds=`tail -10 $OSlog | grep "$ERRORmsg" | wc -l`
if [ $founds -gt 0 ]; then
echo "`date +%d-%b-%Y` `date +%H:%M:%S`: $card Card lost" >> $OStolog
curl -s --digest "$URL/readers.html?label=${card}&action=disable" >/dev/null
curl -s --digest "$URL/readers.html?label=${card}&action=enable" >/dev/null
fi
done
exit 0
Code: Alles auswählen
#!/bin/bash
# Oscam Watchdog & Nagios Script
# -------------------------------
# you can share the script where and as much as you want
# but leave the copyright & contact header untouched!
# if you modify the script you can place your name below
# -------------------------------
# Requires: curl (apt-get install curl)
# wget is not supported cause a failure with authentication encryption
# -------------------------------
# Changelog:
# 15.10.12 - Checken von Entitlements hinzugefügt. Bug im ReaderRestart behoben.
# 15.10.12 - Commandline Howto angepasst. Version auf 0.4 erhöht.
#
#
# -------------------------------
filename="check_oscam"
version="0.4"
# Start
# Konfiguration:
#
# Wert welcher per Commandozeile übergeben werden muss, damit der automatische Restart des Readers erfolgt.
codeRestart="autorestart"
# Anzahl wie oft hintereinander der Reader neugestartet wird bevor abgebrochen wird (falls es danach nicht OK ist)
anticount="3"
# Log 2 Syslog
# "1" Aktiviert
# "0" Deaktiviert
logsyslog="0"
# Debug
# "1" Aktiviert
# "0" Deaktiviert
debug="0"
# Temporärer Pfad
# für html Seiten & Antiloop Dateien
# OHNE abschließendem Slash (/) am Ende
temp="/tmp"
# Der User welcher das Skript ausführt muss Besitzer der Dateien (status.html) und (readers.html) sein.
# (Wenn man das Skript zum Testen mit root ausführt, und später den Cron mit einem anderem User - wird das Skript fehlschlagen, da die Dateien nicht überschrieben werden können.)
# Ende
# Konfiguration
# -------------------------------
howto='\nWarning: Wrong command line arguments. \n
Usage: ./check_oscam <hostname> <port> <username> <password> <part> <autorestart> <reader0> <reader1> ... <reader4> <entitlementsReader0> <entitlementsReader1> ... <entitlementsReader4>\n
Parts are: statuscheck, restart, entitlement\n
Example: ./check_oscam 127.0.0.1 1403 admin "password" statuscheck autorestart hdplus 1702
- Checks the Readers with label hdplus and 1702. If Status != CARDOK the reader will be restarted automatic.\n
Example: ./check_oscam 127.0.0.1 1403 admin "password" statuscheck norestart hdplus 1702
- Checks the Readers with label hdplus and 1702. But with no reader restart.\n
Example: ./check_oscam 127.0.0.1 1403 admin "password" entitlement norestart hdplus 1702 "" "" "" "1" "10"
- Refresh the Entitlements & Checks the Count of Entitlements of reader with label hdplus & 1702 where hdplus should have 1 entitlement and 1702 should have 10 entitlements.
- You can specify a maximum of 5 readers. If you specify not 5 you have to place a "" for each missing before starting with the count of entitlements.
- In the Example above 2 readers are specified so there are 3 placeholders ("" "" "") required until starting with the count of entitlements.
Note: All values are case sensitive!
'
if [ "$#" -lt "6" ]; then
echo -e "$howto" && exit "3"
fi
# General
strHostname=${1}
strPort=${2}
strUser=${3}
strPass=${4}
strpart=${5}
strRestart=${6}
# Reader
strReader0=${7}
strReader1=${8}
strReader2=${9}
strReader3=${10}
strReader4=${11}
# Entitlements
strEnt0=${12}
strEnt1=${13}
strEnt2=${14}
strEnt3=${15}
strEnt4=${16}
if [ "$strpart" == "entitlement" ] && [ "$strEnt0" == "" ]; then
echo -e "$howto" && exit "3"
fi
# Debugging
if [ $debug -eq 1 ] ;then echo -e "Hostname:$strHostname\nPort:$strPort\nUser:$strUser\nPass:******\nPart:$strpart\nRestart:$strRestart\nReader0:$strReader0\nReader1:$strReader1\nReader2:$strReader2\nReader3:$strReader3\nReader4:$strReader4\n---------------------------------\nEntReader0:$strEnt0\nEntReader1:$strEnt1\nEntReader2:$strEnt2\nEntReader3:$strEnt3\nEntReader4:$strEnt4" ; fi
# Remove old File
rm -f ""$temp"/status.html"
statuscheck() {
#echo "$strHostname:$strPort"
rm -f "$temp"/status.html
# File Download
a=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth -o ""$temp"/status.html" "http://$strHostname:$strPort/status.html" >/dev/null 2>/dev/null)
if [ $? -eq 0 ]
then
{ lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')
if [ $lines -lt 2 ] ; then
t=$(tail -n 1 ""$temp"/status.html")
echo "CRITICAL: " $t
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: $t"; fi
if [ $debug -eq 1 ] ;then echo -e "Fehler - Status.html hat >2 Zeilen und sieht somit nicht korrekt aus." ; fi
exit 2;
else
{
# Datei hat mehr als 1 Zeile - also suche nach Karten
c=0
z=0
readerName="strReader"
if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
while [ $z == 0 ]
do
{
# Zähle ReaderNamen hoch
readerNameComp="$readerName$c"
if [ $debug -eq 1 ] ;then echo -e "Readername = readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ; fi
# Suche nach Karte
b=$(grep '<TD class="statuscol16">CARDOK <A HREF="entitlements.html?label='${!readerNameComp}'&hideexpired=1"' "$temp"/status.html)
if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi
if [ $? -eq 0 ]
then
#Grep erfolgreich - aber noch nicht klar ob string gefunden
if [ ! "$b" == "" ]
then
#echo "Karte - OK"
if [ ! "$y" == "NOK" ] ; then y="OK" ; fi
e=""$e"OK: ${!readerNameComp} - "
if [ $debug -eq 1 ] ;then echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
# pattern found
# Alles gut - lösche falls vorhanden die Antiloop Datei
rm -f ""$temp"/${!readerNameComp}"
else
# String nicht gefunden, also Karte nicht OK
#echo "Karte - Not OK"
y=("NOK")
e=""$e"CRITICAL: ${!readerNameComp} - "
if [ "$codeRestart" == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
if [ $debug -eq 1 ] ;then echo -e "Sieht schlecht aus - String nicht gefunden. (1. Abfrage)\ny=$y\ne=$e" ; fi
fi
else
#echo "Karte - Not OK"
y=("NOK")
e=""$e"CRITICAL: ${!readerNameComp} - "
if [ "$codeRestart" == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
if [ $debug -eq 1 ] ;then echo -e "Sieht schlecht aus - String nicht gefunden.(2. Abfrage)\ny=$y\ne=$e" ; fi
fi
# Ende If
tempCount=$[$c + 1]
if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
readerNameComp="$readerName$tempCount"
if [ $debug -eq 1 ] ;then echo -e "Demnach ist der nächste Reader: $readerNameComp\nDas sollte sein:${!readerNameComp}" ; fi
if [ "${!readerNameComp}" == "" ] ; then
z=$[$z + 1]
if [ $debug -eq 1 ] ;then echo -e "So der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
else
# Zähle Reader hoch
c=$[$c + 1]
if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
fi
}
done
if [ "$y" == 'OK' ] ; then
echo "$e"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - $e"; fi
if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
exit 0
fi
if [ "$y" == "NOK" ] ; then
echo "$e"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - $e"; fi
if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = NOK - also Exit 2." ; fi
exit 2
fi
}
fi
}
else
{
echo "CRITICAL: Could not download status.html (StatusCheck)"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
exit 2;
}
fi
}
readerRestart() {
if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Funktion - Übergabewert (Readername) ist: $1" ; fi
# echo "$strHostname:$strPort"
rm -f ""$temp"/readers.html"
# Check das Loop nicht Größer X ist - damit die Reader nicht dauernd neu gestartet werden
r=$(cat "$temp/$1" 2>/dev/null)
if [ ""$r"" == "" ] ; then r=0 ;if [ $debug -eq 1 ] ;then echo -e "Temp. Restartdatei existiert noch nicht. r=$r" ; fi; fi
if [ "$r" -ge "$anticount" ] ; then
echo "CRITICAL: Nach $r Versuchen kein Reader restart mehr."
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: Nach $r Versuchen kein Reader restart mehr."; fi
# if [ $debug -eq 1 ] ;then echo -e "$filename $version - CRITICAL: Nach $r Versuchen kein Reader restart mehr." ; fi
# Deaktiviert, da sonst das Skript komplett beendet wird
# exit 2;
else
# File Download
if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. befehl disable befehl ausgeführt" ; fi
g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth -o ""$temp"/readers.html" "http://$strHostname:$strPort/readers.html?label=$1&action=disable" >/dev/null 2>/dev/null)
if [ $? -eq 0 ]
then
# Antiloop hochzählen
echo $[$r+1] > "$temp/$1"
# Zähle Zeilen um Fehler fest zu stellen ( Datei muss <1 Zeile sein )
lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
if [ $lines -lt 2 ] ; then
s=$(tail -n 1 ""$temp"/readers.html")
echo "CRITICAL: " $s
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: $s"; fi
# Deaktiviert, da sonst das Skript komplett beendet wird
# exit 2;
else
# Datei hat mehr als 1 Zeile - also suche nach Karten
echo "WARNING: Reader $1 disabled"
# Aufräumen vor dem aktivieren
rm -f ""$temp"/readers.html"
lines=""
s=""
f=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth -o ""$temp"/readers.html" "http://$strHostname:$strPort/readers.html?label=$1&action=enable" >/dev/null 2>/dev/null)
if [ $? -eq 0 ]
then
lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
if [ $lines -lt 2 ] ; then
s=$(tail -n 1 ""$temp"/readers.html")
echo "CRITICAL: " $s
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: $s"; fi
# Deaktiviert, da sonst das Skript komplett beendet wird
# exit 2;
else
# Datei hat mehr als 1 Zeile - also suche nach Karten
echo "WARNING: Reader $1 enabled"
#sleep 10
#statuscheck
fi
fi
fi
else
echo "CRITICAL: Could not download readers.html (ReaderRestart)"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: Could not download readers.html (ReaderRestart)"; fi
# Deaktiviert, da sonst das Skript komplett beendet wird
# exit 2;
fi
fi
# -------------------------------------------------------------------
}
entitlement() {
#echo "$strHostname:$strPort"
y=""
e=""
rm -f "$temp"/status.html
# Aktualisiere Entitlements
if [ ! "$strReader0" == "" ] ; then refreshEntitlement $strReader0 ; fi
if [ ! "$strReader1" == "" ] ; then refreshEntitlement $strReader1 ; fi
if [ ! "$strReader2" == "" ] ; then refreshEntitlement $strReader2 ; fi
if [ ! "$strReader3" == "" ] ; then refreshEntitlement $strReader3 ; fi
if [ ! "$strReader4" == "" ] ; then refreshEntitlement $strReader4 ; fi
# File Download
a=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth -o ""$temp"/status.html" "http://$strHostname:$strPort/status.html" >/dev/null 2>/dev/null)
if [ $? -eq 0 ]
then
{ lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')
if [ $lines -lt 2 ] ; then
t=$(tail -n 1 ""$temp"/status.html")
echo "CRITICAL: " $t
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: $t"; fi
if [ $debug -eq 1 ] ;then echo -e "Fehler - Status.html hat >2 Zeilen und sieht somit nicht korrekt aus." ; fi
exit 2;
else
{
# Datei hat mehr als 1 Zeile - also suche nach Entitlements
c=0
z=0
readerName="strReader"
entName="strEnt"
if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife um nach Entitlements zu suchen.\nc=$c\nz=$z\nreaderName=$readerName\nEntitleName=$entName" ; fi
while [ $z == 0 ]
do
{
# Zähle Reader/Entitlement hoch
readerNameComp="$readerName$c"
entNameComp="$entName$c"
if [ $debug -eq 1 ] ;then echo -e "Readername = readerNameComp="$readerNameComp"\nReadernameREAL="${!readerNameComp}"\nEntitleName="$entNameComp"\nEntitlementREAL="${!entNameComp}"" ; fi
# Checke ob 1 oder mehr Entitlements
if [ "${!entNameComp}" -eq "1" ] ;then
entitleCount="entitlement"
else
entitleCount="entitlements"
fi
# Suche nach Entitlement
b=$(grep '<A HREF="entitlements.html?label='${!readerNameComp}'&hideexpired=1" class="tooltip">('${!entNameComp}' '$entitleCount')<SPAN>' "$temp"/status.html)
if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi
if [ $? -eq 0 ]
then
#Grep erfolgreich - aber noch nicht klar ob string gefunden
if [ ! "$b" == "" ]
then
#echo "Entitlement - OK"
if [ ! "$y" == "NOK" ] ; then y="OK" ; fi
e=""$e"OK: ${!readerNameComp} ("${!entNameComp}" $entitleCount) - "
if [ $debug -eq 1 ] ;then echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
else
# String nicht gefunden, also Entitlements nicht OK
y=("NOK")
e=""$e"CRITICAL: ${!readerNameComp} (${!entNameComp} $entitleCount) - "
if [ $debug -eq 1 ] ;then echo -e "Sieht schlecht aus - String nicht gefunden. (1. Abfrage)\ny=$y\ne=$e" ; fi
fi
else
#echo "Karte - Not OK"
y=("NOK")
e=""$e"CRITICAL: ${!readerNameComp} (${!entNameComp} $entitleCount) - "
if [ $debug -eq 1 ] ;then echo -e "Sieht schlecht aus - String nicht gefunden.(2. Abfrage)\ny=$y\ne=$e" ; fi
fi
# Ende If
tempCount=$[$c + 1]
if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
readerNameComp="$readerName$tempCount"
entNameComp="$entName$tempCount"
if [ $debug -eq 1 ] ;then echo -e "Demnach ist der nächste Reader: $readerNameComp\nDas sollte sein:${!readerNameComp}" ; fi
if [ "${!readerNameComp}" == "" -o "${!entNameComp}" == "" ] ; then
z=$[$z + 1]
if [ $debug -eq 1 ] ;then echo -e "So der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
else
# Zähle Reader hoch
c=$[$c + 1]
if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
fi
}
done
if [ "$y" == 'OK' ] ; then
echo "$e"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - $e"; fi
if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
exit 0
fi
if [ "$y" == "NOK" ] ; then
echo "$e"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - $e"; fi
if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = NOK - also Exit 2." ; fi
exit 2
fi
}
fi
}
else
{
echo "CRITICAL: Could not download status.html (StatusCheck)"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
exit 2;
}
fi
}
refreshEntitlement() {
if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Entitlement Funktion" ; fi
# echo "$strHostname:$strPort"
rm -f ""$temp"/readers.html"
# File Download
if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. refresh befehl ausgeführt" ; fi
g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth -o ""$temp"/readers.html" "http://$strHostname:$strPort/readers.html?label=$1&action=reread" >/dev/null 2>/dev/null)
if [ $? -eq 0 ]
then
# Antiloop hochzählen
echo $[$r+1] > "$temp/$1"
# Zähle Zeilen um Fehler fest zu stellen ( Datei muss <1 Zeile sein )
lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
if [ $lines -lt 2 ] ; then
s=$(tail -n 1 ""$temp"/readers.html")
echo "CRITICAL: " $s
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: $s"; fi
# Deaktiviert, da sonst das Skript komplett beendet wird
# exit 2;
else
if [ $debug -eq 1 ] ;then echo "OK: Entitlement Refresh" ; fi
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - OK: Entitlement Refresh von $1"; fi
fi
else
echo "CRITICAL: Could not download readers.html (ReaderRefresh)"
# Logging
if [ "$logsyslog" == "1" ] ; then logger "$filename $version - CRITICAL: Could not download readers.html (ReaderRefresh)"; fi
# Deaktiviert, da sonst das Skript komplett beendet wird
# exit 2;
fi
# -------------------------------------------------------------------
}
if [ "$strpart" == "statuscheck" ]; then
statuscheck
elif [ "$strpart" == "entitlement" ]; then
entitlement
elif [ "$strpart" == "restart" ]; then
c=0
z=0
readerName="strReader"
if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
while [ $z == 0 ]
do
{
# Zähle ReaderNamen hoch
readerNameComp="$readerName$c"
if [ $debug -eq 1 ] ;then echo -e "Readername = readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ; fi
# Code
readerRestart ${!readerNameComp}
# Count up
tempCount=$[$c + 1]
if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
readerNameComp="$readerName$tempCount"
if [ $debug -eq 1 ] ;then echo -e "Demnach ist der nächste Reader: $readerNameComp\nDas sollte sein:${!readerNameComp}" ; fi
if [ "${!readerNameComp}" == "" ] ; then
z=$[$z + 1]
if [ $debug -eq 1 ] ;then echo -e "So der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
else
# Zähle Reader hoch
c=$[$c + 1]
if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
fi
}
done
fi
# Ende Skript
# Oscam Watchdog & Nagios Script
# -------------------------------
Funktionen:
- Überpüft auf CARDOK von bis zu 5 Readern
- Kann sofern eingestellt Reader bei nicht CARDOK neu starten
- Kann die Anzahl an Entitlements pro Karte überprüfen
- Rückmeldung inkl. Exit Codes
Code: Alles auswählen
chmod +x /var/emu/script/check.reader
Code: Alles auswählen
i jobs
Code: Alles auswählen
* * * * * root /var/emu/script/check.reader #check reader (jede Minute)
Code: Alles auswählen
2012/10/27 10:05:57 160E868 r skygermany [smartreader] found cardsystem videoguard2
2012/10/27 10:05:57 160E868 r skygermany [videoguard2] card detected
2012/10/27 10:05:57 160E868 r skygermany [videoguard2] type: VideoGuard Sky Germany (09C4)
2012/10/27 10:05:57 160E868 r skygermany [smartreader] Doing fast reset
2012/10/27 10:05:58 160E868 r skygermany [smartreader] ATR: XX XX XX XX XX XX XX XX XX XX
2012/10/27 10:05:59 160E868 r skygermany [smartreader] Maximum frequency for this card is formally 5 Mhz, clocking it to 4.80 Mhz
2012/10/27 10:06:02 160E868 r skygermany [smartreader] card system not supported
2012/10/27 10:06:02 160E868 r skygermany [smartreader] Normal mode failed, reverting to Deprecated Mode
2012/10/27 10:06:02 160E868 r skygermany [smartreader] Doing fast reset
2012/10/27 10:06:03 160E868 r skygermany [smartreader] Error activating card.
2012/10/27 10:06:03 160E868 r skygermany [smartreader] Doing fast reset
2012/10/27 10:06:04 160E868 r skygermany [smartreader] Error activating card.
2012/10/27 10:06:05 160E868 r skygermany [smartreader] Doing fast reset
2012/10/27 10:06:06 160E868 r skygermany [smartreader] Error activating card.
2012/10/27 10:06:06 160E868 r skygermany [smartreader] card initializing error
Code: Alles auswählen
## monitoring Error message
OSerror="ERROR Phoenix_GetStatus: ioctl error in card detection for %CARDNAME%"
Code: Alles auswählen
## monitoring Error message
OSerror="%CARDNAME% [smartreader] card initializing error"
Code: Alles auswählen
## monitoring Error message
OSerror="%CARDNAME% [smartreader] card initializing error"
Hallo,Code: Alles auswählen
## monitoring Error message OSerror="%CARDNAME% [smartreader] card initializing error"
Code: Alles auswählen
2013/04/21 20:26:25 1822370 r hdplus [smartreader] card detected
2013/04/21 20:26:30 1822370 r hdplus [smartreader] Error activating card.
2013/04/21 20:26:43 1822370 r hdplus [smartreader] card initializing error
Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast