Oscam Cardserver überwachen (Rapberry): Unterschied zwischen den Versionen

Aus Tutorials
Zur Navigation springen Zur Suche springen
Zeile 80: Zeile 80:
'
'
if [ "$#" -lt "6" ]; then
if [ "$#" -lt "6" ]; then
        echo -e "$howto" && exit "3"
  echo -e "$howto" && exit "3"
fi
fi


Zeile 107: Zeile 107:


if [ "$strpart" == "entitlement" ] && [ "$strEnt0" == "" ]; then
if [ "$strpart" == "entitlement" ] && [ "$strEnt0" == "" ]; then
        echo -e "$howto" && exit "3"
  echo -e "$howto" && exit "3"
fi
fi


Zeile 119: Zeile 119:


statuscheck() {
statuscheck() {
    #echo "$strHostname:$strPort"
  #echo "$strHostname:$strPort"
    rm -f "$temp"/status.html
  rm -f "$temp"/status.html
    # File Download
  # 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)
  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 ]
  if [ $? -eq 0 ]
    then
  then
    {        lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')
  {         
    lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')


            if [ $lines -lt 2 ] ; then
    if [ $lines -lt 2 ]; then
                t=$(tail -n 1 ""$temp"/status.html")
      t=$(tail -n 1 ""$temp"/status.html")
                echo "CRITICAL: " $t
      echo "CRITICAL: " $t
                    # Logging
      # Logging
                        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $t"; fi
      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
      if [ $debug -eq 1 ] ;then echo -e "Fehler - Status.html hat <2 Zeilen und sieht somit nicht korrekt aus." ; fi


                exit 2;
      exit 2;
            else
    else
            {
    {
                # Datei hat mehr als 1 Zeile - also suche nach Karten
      # Datei hat mehr als 1 Zeile - also suche nach Karten
                    c=0
      c=0
                    z=0
      z=0
                    readerName="strReader"
      readerName="strReader"
                    if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife  um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
      if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife  um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
                    while [ $z == 0 ]
      while [ $z == 0 ]
                    do
      do
                        {
      {
                            # Zähle ReaderNamen hoch
        # Zähle ReaderNamen hoch
                            readerNameComp="$readerName$c"
        readerNameComp="$readerName$c"
                            if [ $debug -eq 1 ] ;then echo -e  "Readername = readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ; fi
        if [ $debug -eq 1 ] ;then echo -e  "Readername = readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ; fi


                            # Suche nach Karte
        # Suche nach Karte
                            b=$(grep '<TD CLASS="statuscol16">CARDOK<BR><A HREF="entitlements.html?label='${!readerNameComp}'&amp;hideexpired=1"' "$temp"/status.html)
        b=$(grep '<TD CLASS="statuscol16">CARDOK<BR><A HREF="entitlements.html?label='${!readerNameComp}'&amp;hideexpired=1"' "$temp"/status.html)
                            if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi
        if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi
                            if [ $? -eq 0 ]
        if [ $? -eq 0 ]; then
                                then
          #Grep erfolgreich - aber noch nicht klar ob string gefunden
                                        #Grep erfolgreich - aber noch nicht klar ob string gefunden
          if [ ! "$b" == "" ]; then
                                        if [ ! "$b" == "" ]
            #echo "Karte - OK"
                                        then
            if [ ! "$y" == "NOK" ] ; then  y="OK" ; fi
                                            #echo "Karte - OK"
            e=""$e"OK: ${!readerNameComp} - "
                                            if [ ! "$y" == "NOK" ] ; then  y="OK" ; fi
            if [ $debug -eq 1 ] ;then  echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
                                            e=""$e"OK: ${!readerNameComp} - "
            # pattern found
                                            if [ $debug -eq 1 ] ;then  echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
            # Alles gut - lösche falls vorhanden die Antiloop Datei
                                            # pattern found
            rm -f ""$temp"/${!readerNameComp}"
                                            # Alles gut - lösche falls vorhanden die Antiloop Datei
          else
                                            rm -f ""$temp"/${!readerNameComp}"
            # String nicht gefunden, also Karte nicht OK
                                        else
            #echo "Karte - Not OK"
                                            # String nicht gefunden, also Karte nicht OK
            y=("NOK")
                                            #echo "Karte - Not OK"
            e=""$e"CRITICAL: ${!readerNameComp} - "
                                            y=("NOK")
            if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
                                            e=""$e"CRITICAL: ${!readerNameComp} - "
            if [ $debug -eq 1 ] ;then  echo -e "Sieht schlecht aus - String nicht gefunden. (1.  Abfrage)\ny=$y\ne=$e" ; fi
                                            if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
          fi
                                            if [ $debug -eq 1 ] ;then  echo -e "Sieht schlecht aus - String nicht gefunden. (1.  Abfrage)\ny=$y\ne=$e" ; fi
        else
                                        fi
          #echo "Karte - Not OK"
                                else
          y=("NOK")
                                        #echo "Karte - Not OK"
          e=""$e"CRITICAL: ${!readerNameComp} - "
                                        y=("NOK")
          if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
                                        e=""$e"CRITICAL: ${!readerNameComp} - "
          if [ $debug -eq 1 ] ;then echo  -e "Sieht schlecht aus - String nicht gefunden.(2. Abfrage)\ny=$y\ne=$e"  ; fi
                                        if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
        fi # Ende If
                                        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


                            tempCount=$[$c + 1]
        if [ "${!readerNameComp}" == "" ]; then
                            if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
          z=$[$z + 1]
                            readerNameComp="$readerName$tempCount"
          if [ $debug -eq 1 ] ;then echo -e "So  der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
                            if [ $debug -eq 1 ] ;then echo -e "Demnach  ist der nächste Reader: $readerNameComp\nDas sollte sein: ${!readerNameComp}" ; 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 [ "${!readerNameComp}" == "" ] ; then
      if [ "$y" == 'OK' ]; then
                                z=$[$z + 1]
        echo "$e"
                                if [ $debug -eq 1 ] ;then echo -e "So  der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
        # Logging
                            else
        if [ "$logsyslog"  == "1" ] ; then   logger  "$filename $version - $e"; fi
                                # Zähle Reader hoch
        if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
                                c=$[$c + 1]
        exit 0
                                if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
      fi
                            fi
                        }
                    done


                    if [ "$y"  == 'OK' ] ; then
      if [ "$y" == "NOK" ]; then
                        echo "$e"
        echo "$e"
                        # Logging
        # Logging
                                if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
                                if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
        if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = NOK - also Exit 2." ; fi
                        exit 0
        exit 2
                    fi
      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
     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
}
}



Version vom 9. Dezember 2023, 13:27 Uhr

Noch in Bearbeitung


Script

sudo touch /usr/local/bin/check_oscam.sh
sudo chmod a+x /usr/local/bin/check_oscam.sh
sudo vi /usr/local/bin/check_oscam.sh


Medium:Check oscam.zip

#!/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<BR><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
# -------------------------------

Aufruf

./check_oscam.sh 10.0.0.171 8888 <user> "<password>" statuscheck norestart HD%2b

Service erstellen

...

Links

https://www.digital-eliteboard.com/threads/oscam-reader-ueberwachen.240969/


Zurück zu OSCam (Raspberry), Watchdog (OSCam), OSCam (Linux)