HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //lib/python2.7/site-packages/lap/stfc_naps_available.py
#
import subprocess
import os
import re
import sys,linecache, types, time

_tries=3
_sleep=5

def __run__(params):

    try:
        nap = params.get("nap")
        norm = int(params.get("norm"))
        warn = int(params.get("warn"))
        crit = int(params.get("crit"))
    except Exception, e:
        return [2, "CRITICAL - Error getting params: %s" % repr(e)]

    try:
        count = 0
        if os.path.isfile("/tmp/kmedias_stats.txt"):
            _ct=0
            while _ct < _tries:
                kmedias_stats=open("/tmp/kmedias_stats.txt")
                data = kmedias_stats.read()
                kmedias_stats.close()
                r = re.search(re.escape(nap)+' available_cnt=([0-9]+)', data)
                if not isinstance(r, types.NoneType):
                   count = int(r.group(1))
                   break
                else:
                    _ct+=1
                    time.sleep(_sleep)
            if _ct == 3:
                return [2, "CRITICAL - regexp failed(3x5s): %s" % nap+' available_cnt=([0-9]+)']

        else:
            return [2, "CRITICAL - kmedias stats file does not exist: %s" % repr(e)]

        if count == norm:
            return [0, "OK - %s - Channels availables: %s" % (nap,count)]

        if count >= warn and count < norm:
            return [1, "WARN - %s -Channels availables: %s" % (nap,count)]
        else:
            return [2, "CRIT - %s - Channels availables: %s" % (nap,count)]

    except Exception, e:
        exc_type, exc_obj, tb = sys.exc_info()
        f = tb.tb_frame
        lineno = tb.tb_lineno
        filename = f.f_code.co_filename
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        return [2, 'Exception in ({}, line {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)]


#if __name__ == '__main__':
#
#    ''' test only '''
#    params = {
#       "nap": 'NAP_TLF_LD_8198',
#       "norm": 92,
#       "warn": 62,
#       "crit": 31
#    }
#
#    print __run__(params)