OSCam Client-Verbindung überwachen (Satreceiver): Unterschied zwischen den Versionen

Aus Tutorials
Zur Navigation springen Zur Suche springen
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 2: Zeile 2:




== Parameter im File ==
{{note|Funktioniert noch nicht - Client ist direkt nach dem Startup noch nicht erstellt}}


<pre>
#!/bin/bash
#
# -------------------------------
# Requires: curl (opkg install curl)
# -------------------------------
# Changelog:
#
# -------------------------------
filename="check_oscam_client"


client="GigaBlue UHD QUAD 4K (receiver-seestadt)"
== Script ==


# Debug
<pre>
# "1" Aktiviert
touch /usr/script/check_oscam_client.sh
# "0" Deaktiviert
chmod +x /usr/script/check_oscam_client.sh
debug="1"
vi /usr/script/check_oscam_client.sh
 
# Temporärer Pfad OHNE abschließendem Slash (/) am Ende
temp="/tmp"
 
# General
strHostname=<hostname>
strPort=83
strUser=<user>
strPass=<password>
strClientcount=<count>
 
# -------------------------------
#echo "$strHostname:$strPort:$strUser:$strPass:$strClientcount"
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
    {
s='<P id="chead">Clients <span id="ucs">'${strClientcount}'</span>/<span id="uca">1</span></P><DIV>';
#echo "s="$s"";
        g=$(grep "$s" "$temp"/status.html)
        if [ $debug -eq 1 ] ; then echo -e "Suchstring="$g""; fi
if [ $? -eq 0 ]
        then
            #Grep erfolgreich - aber noch nicht klar ob string gefunden
            if [ ! "$g" == "" ]
            then
                if [ $debug -eq 1 ] ;then echo -e "Sieht gut aus - String $s wurde gefunden." ; fi
echo -e "OSCAM client of $client is working at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client are currently working" admin@kirner.or.at
            else
                if [ $debug -eq 1 ] ;then echo -e  "Sieht schlecht aus - String $s nicht gefunden." ;  fi
echo -e "OSCAM client of $client restarted at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client restarted" admin@kirner.or.at
            fi
        else
            if [ $debug -eq 1 ] ;then echo -e "Sieht  schlecht aus - String $s nicht gefunden." ; fi
        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
</pre>
</pre>
== Parameter als Argumente ==


<pre>
<pre>
Zeile 116: Zeile 38:


if [ "$#" -lt "5" ]; then
if [ "$#" -lt "5" ]; then
    echo -e "$howto" && exit "3"
  echo -e "$howto" && exit "3"
fi
fi


Zeile 127: Zeile 49:


#echo "$strHostname:$strPort:$strUser:$strPass:$strClientcount"
#echo "$strHostname:$strPort:$strUser:$strPass:$strClientcount"
rm -f "$temp"/screenshot.html
rm -f "$temp"/status.html
rm -f "$temp"/status.html


# File Download
# File Download
curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/screenshot.html" "http://$strHostname/#/screenshot"  >/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)
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;
  }
  else
  {
    s='<P id="chead">Clients <span id="ucs">'${strClientcount}'</span>/<span id="uca">1</span></P><DIV>';
    #echo "s="$s"";
 
    g=$(grep "$s" "$temp"/status.html)
    if [ $debug -eq 1 ] ; then echo -e "Suchstring="$g""; fi


         exit 2;
    if [ $? -eq 0 ]
}
    then
      #Grep erfolgreich - aber noch nicht klar ob string gefunden
      if [ ! "$g" == "" ]
      then
         if [ $debug -eq 1 ] ;then echo -e "Sieht gut aus - String $s wurde gefunden." ; fi
        echo -e "OSCAM client of $client is working at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client are currently working" admin@kirner.or.at
      else
        if [ $debug -eq 1 ] ;then echo -e  "Sieht schlecht aus - String $s nicht gefunden." ;  fi
 
        // TODO add restart logic
 
        echo -e "OSCAM client of $client restarted at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client restarted" admin@kirner.or.at
      fi
     else
     else
    {
      if [ $debug -eq 1 ] ;then echo -e "Sieht  schlecht aus - String $s nicht gefunden." ; fi
s='<P id="chead">Clients <span id="ucs">'${strClientcount}'</span>/<span id="uca">1</span></P><DIV>';
    fi
#echo "s="$s"";
  }
  fi
        g=$(grep "$s" "$temp"/status.html)
        if [ $debug -eq 1 ] ; then echo -e "Suchstring="$g""; fi
if [ $? -eq 0 ]
        then
            #Grep erfolgreich - aber noch nicht klar ob string gefunden
            if [ ! "$g" == "" ]
            then
                if [ $debug -eq 1 ] ;then echo -e "Sieht gut aus - String $s wurde gefunden." ; fi
echo -e "OSCAM client of $client is working at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client are currently working" admin@kirner.or.at
            else
                if [ $debug -eq 1 ] ;then echo -e  "Sieht schlecht aus - String $s nicht gefunden." ;  fi
echo -e "OSCAM client of $client restarted at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client restarted" admin@kirner.or.at
            fi
        else
            if [ $debug -eq 1 ] ;then echo -e "Sieht  schlecht aus - String $s nicht gefunden." ; fi
        fi
    }
fi
}
}
else
else
{
{
    echo "CRITICAL: Could not download status.html (StatusCheck)"
  echo "CRITICAL: Could not download status.html (StatusCheck)"
    # Logging
  # Logging
    if [ "$logsyslog"  == "1" ] ; then logger "$filename $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
  if [ "$logsyslog"  == "1" ] ; then logger "$filename $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
    exit 2;
  exit 2;
}
}
fi
fi
</pre>
== Init-Script erstellen ==
<pre>
touch /etc/init.d/run_check_oscam_client.sh
chmod a+x /etc/init.d/run_check_oscam_client.sh
vi /etc/init.d/run_check_oscam_client.sh
</pre>
<pre>
sleep 20 && /usr/script/check_oscam_client.sh <hostname> 83 <username> <password> 1
</pre>
</pre>


<pre>
<pre>
  314  vi /usr/script/check_oscam_client.sh
cd /etc/rc3.d/
  315  chmod +x /usr/script/check_oscam_client.sh
ln -sf ../init.d/run_check_oscam_client.sh /etc/rc3.d/S99run_check_oscam_client.sh
  316  ls -la  /usr/script/check_oscam_client.sh
  317  ln -sf /usr/script/check_oscam_client.sh /etc/init.d/check_oscam_client.sh
  318  ls -la /etc/init.d/
  319  cd /etc/rc3.d/
  320  ls -la
  321  ln -sf ../init.d/check_oscam_client.sh /etc/rc3.d/S100check_oscam_client.sh
</pre>
</pre>




Zurück zu [[Watchdog_(Oscam)#OSCam_Client-Verbindung_überwachen|Watchdog (Oscam)]]
Zurück zu [[Watchdog_(Oscam)#OSCam_Client-Verbindung_überwachen|Watchdog (Oscam)]]

Aktuelle Version vom 5. Dezember 2023, 19:15 Uhr

Noch in Bearbeitung


Funktioniert noch nicht - Client ist direkt nach dem Startup noch nicht erstellt


Script

touch /usr/script/check_oscam_client.sh
chmod +x /usr/script/check_oscam_client.sh
vi /usr/script/check_oscam_client.sh
#!/bin/bash
#
# -------------------------------
# Requires: curl (opkg install curl)
# -------------------------------
# Changelog:
#
# -------------------------------
filename="check_oscam_client"

client="GigaBlue UHD QUAD 4K (receiver-seestadt)"

# Debug
# "1" Aktiviert
# "0" Deaktiviert
debug="0"

# Temporärer Pfad OHNE abschließendem Slash (/) am Ende
temp="/tmp"

# -------------------------------
howto='\nUsage: ./check_oscam_client <hostname> <port> <username> <password> <clientcount>'

if [ "$#" -lt "5" ]; then
  echo -e "$howto" && exit "3"
fi

# General
strHostname=${1}
strPort=${2}
strUser=${3}
strPass=${4}
strClientcount=${5}

#echo "$strHostname:$strPort:$strUser:$strPass:$strClientcount"
rm -f "$temp"/screenshot.html
rm -f "$temp"/status.html

# File Download
curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/screenshot.html" "http://$strHostname/#/screenshot"  >/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 ]
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
  {
    s='<P id="chead">Clients <span id="ucs">'${strClientcount}'</span>/<span id="uca">1</span></P><DIV>';
    #echo "s="$s"";

    g=$(grep "$s" "$temp"/status.html)
    if [ $debug -eq 1 ] ; then echo -e "Suchstring="$g""; fi

    if [ $? -eq 0 ]
    then
      #Grep erfolgreich - aber noch nicht klar ob string gefunden
      if [ ! "$g" == "" ]
      then
        if [ $debug -eq 1 ] ;then echo -e "Sieht gut aus - String $s wurde gefunden." ; fi
        echo -e "OSCAM client of $client is working at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client are currently working" admin@kirner.or.at
      else
        if [ $debug -eq 1 ] ;then echo -e  "Sieht schlecht aus - String $s nicht gefunden." ;  fi

        // TODO add restart logic

        echo -e "OSCAM client of $client restarted at `date +"'%d.%m.%Y %H:%M'"`" | /usr/bin/mailx -A kirner.or.at -s "OSCAM client of $client restarted" admin@kirner.or.at
      fi
    else
      if [ $debug -eq 1 ] ;then echo -e "Sieht  schlecht aus - String $s nicht gefunden." ; fi
    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

Init-Script erstellen

touch /etc/init.d/run_check_oscam_client.sh
chmod a+x /etc/init.d/run_check_oscam_client.sh
vi /etc/init.d/run_check_oscam_client.sh
sleep 20 && /usr/script/check_oscam_client.sh <hostname> 83 <username> <password> 1
cd /etc/rc3.d/
ln -sf ../init.d/run_check_oscam_client.sh /etc/rc3.d/S99run_check_oscam_client.sh


Zurück zu Watchdog (Oscam)