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/postgresql_barman_backup.py
import subprocess

from dateutil.parser import parse

# check postgresql barman backup
# we can use it to monitor the backup
def __run__(params):

    # gerando list de servidores
    def list_server():

        barman_list = subprocess.Popen(['sudo', 'barman', 'list-server'], stdout=subprocess.PIPE)
        list_servers = barman_list.communicate()

        return list_servers

    # executando barman check
    def check_server(host):

        list_check_server = []
        priority = 0

        p = subprocess.Popen(['sudo', 'barman', 'check', host, '--nagios'], stdout=subprocess.PIPE)
        list_check_server.append(p.communicate()[0])
        for line in list_check_server:
            if 'FAILED' in line:
                if 'backup maximum age' in line:
                    priority = 3
                else:
                    priority = 2

        return priority

    # executando barman list-backup
    def list_backups(host):
        
        hosts = ''
        priority = 0

        p = subprocess.Popen(['sudo', 'barman', 'list-backup', host], stdout=subprocess.PIPE)
        a = p.communicate()[0]
       
        # verificando se existe backup para o host
        if a:
            backup= a.splitlines()[0]

        else:
            hosts += host
            priority = 2

        return priority


    hosts = list_server()
    list_check_servers = []

    for host in hosts[0].splitlines():
        ret = check_server(host)
        list_check_servers.append((ret, host))
        #ret = list_backups(host)
        #list_check_servers.append((ret, host))

    errors = filter(lambda x: x[0] == 3, list_check_servers)
    if errors:
        servers = []
        for _, host in errors:
            if host not in servers:
                servers.append(host)
        return [2, 'Hosts com backup fora da retencao: {0}' .format(servers)]
        
    errors = filter(lambda x: x[0] == 2, list_check_servers)
    if errors:
        servers = []
        for _, host in errors:
            if host not in servers:
                servers.append(host)
        return [2, 'Hosts com backup em execucao a mais de 1 dia: {0}' .format(servers)]
 
    warnings = filter(lambda x: x[0] == 1, list_check_servers)
    if warnings:
        servers = []
        for _, host in warnings:
            if host not in servers:
                servers.append(host)
        return [1, 'Backup em execucao no host: {0}' .format(servers)]
 
    return [0, 'Backup OK']


if __name__ == '__main__':
    print __run__({})