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/bacula_error_full.py
#!/usr/bin/python

from backupmanager import BackupAPI
import socket
import json
from datetime import datetime,timedelta
import argparse
import sys,os
import time
from random import randrange
import pwd, grp

auth = BackupAPI()
client = socket.gethostname().split('.')[0]
OK = 0
CRITICAL = 2
WARNING = 1
cache_file = "/tmp/bacula_full.cache"
cache_time = 10700 + randrange(100)


def user_cache():
    try:
        uid, gid =  pwd.getpwnam('check-mk').pw_uid, grp.getgrnam('check-mk').gr_gid
        if uid and gid:
            os.chown(cache_file, uid, gid)
            
    except KeyError:
        pass

def cegonha(client, full_json):
    if full_json['status'] in ["IN_PRODUCTION","SPARE_INSTALATION","SPARE_MAINTAINCE","PRE_PRODUCTION","MAINTENANCE"] and full_json['flag'] == True:
        return True
    else:
        return False

def __run__(params):
    lista = []
    if os.path.isfile(cache_file) and (time.time() - os.stat(cache_file).st_mtime) < cache_time and \
                                  os.stat(cache_file).st_size > 0:
        data = json.loads(open(cache_file).read())

        if data:
            return [OK, "Cache " + data]
        else:
            return [CRITICAL, "Cache " + data]

    else:
        with open(cache_file, 'w') as f:
            user_cache()
            try:
                full_json = auth.login('cegonha', client)
                if cegonha(client, full_json):
                    jobs = auth.login('rotina', client)
    
                    if jobs:
                       for job in jobs:
                            error = auth.login('lasterror', job)
                            full_error = error['full_error']  
    
                            if full_error:
                                auth.login('reviewed', job + "/full")
                                lista.append({job: full_error})
    
                       if lista:
                           return [CRITICAL, "Client %s with erros in the jobs %s " % (client, lista)]
                       else:
                           msg = "Backup OK"
                           f.write(json.dumps(msg))
                           return [OK, msg]
                    else:
                        msg = "OK: Client %s does not exist in backupmanager" % client
                        f.write(json.dumps(msg))
                        return [OK, msg]
                else:
                    msg = "Machine flag false or desactived"
                    f.write(json.dumps(msg))
                    return [OK, msg]
    
            except Exception, e:
                   return [WARNING, "WARNING: API Connection refused"]