Monitor OSCam with check_mk

A simple check for check_mk to monitor OSCam.
Queries the xmlAPI of oscam and mangels the output to match check_mk’s expectation.

Tested on

OSCAM: 1.20-unstable_svn Build: r9783 Compiler: x86_64-linux-gnu

Setup

Find your local script path

$ check_mk -d <monitored_host>| head
<<<check_mk>>>
Version: 1.2.4p5
AgentOS: linux
PluginsDirectory: /usr/lib/check_mk_agent/plugins
LocalDirectory: /usr/lib/check_mk_agent/local
...

Put the Script in place on your oscam server

  • Copy & paste the script below to LocalDirectory
  • Change the API connection details
  • Change the service status definitions if you want to
  • Run an inventory scan on your monitoring system:

    # check_mk -I <monitored_host>
    local             1 new checks

    oscam.py

    #!/usr/bin/python
     
    import requests
    from requests.auth import HTTPDigestAuth
    import xmltodict
     
    # API connection details
    url      = 'http://localhost:16002/oscamapi.html?part=status'
    username = ''
    password = ''
     
    # define service status by "bad" cards
    ok   = '0';   # service is OK if 0 bad cards
    warn = '4';   # service is WARN if greather or equal than n bad card
     
     
    filtered = dict()
     
    def receive():
      data = requests.get(url, auth=HTTPDigestAuth(username, password)).content
      data = xmltodict.parse(data)
      return data
     
    def filter(e, filtered):
      if e['@type'] == 'p' or e['@type'] == 'r':
        filtered[e['@name']] = e['connection']['#text']
     
     
     
    xml = receive()
    for i in xml['oscam']['status']['client']:
      filter(i, filtered)
     
     
    cardsTotal = len(filtered)
    cardsGood = sum(1 for x in filtered.values() if x == 'CARDOK' or x == 'CONNECTED')
    cardsBad = cardsTotal - cardsGood
     
    state = 0
    if cardsTotal - cardsGood >= warn:
      state = 1
    if filtered['easymouse-local'] != 'CARDOK':
      state = 2
     
    print '%d oscam_cards count=%d|good=%d|bad=%d %d cards, %d bad, %d good' % (state, cardsTotal, cardsGood, cardsBad, cardsTotal, cardsBad, cardsGood)

    Leave a Reply

    Your email address will not be published / Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.