Ejemplo n.º 1
0
 def getStatus(self):
     server = urbackup_api.urbackup_server("http://{server}:55414/x".format(
             server = self.host,
         ), 
         self.user, 
         self.passwd
     )
     return server.get_status()
Ejemplo n.º 2
0
def main():
    """
    ./urbackup_stats.py http://127.0.0.1/x myuser mypwd
    """
    urbackup_server_address = sys.argv[1]
    if len(sys.argv) > 2:
        urbackup_server_user = sys.argv[2]
    else:
        urbackup_server_user = None
    if len(sys.argv) > 3:
        urbackup_server_pw = sys.argv[3]
    else:
        urbackup_server_pw = None

    server = urbackup_api.urbackup_server(urbackup_server_address,
                                          urbackup_server_user,
                                          urbackup_server_pw)
    clients = server.get_status()
    for client in clients:
        last_backup_file = client['lastbackup']
        last_backup_image = client['lastbackup_image']
        status = client['status']
        client['os_version_string'] = str_escape(client['os_version_string'])
        client['name'] = str_escape(client['name'])
        client['os_simple'] = str_escape(client['os_simple'])
        client['client_version_string'] = str_escape(
            client['client_version_string'])
        if client['ip'] == "-":
            client['ip'] = None
        client.pop('lastbackup')
        client.pop('lastbackup_image')
        client.pop('processes')
        client.pop('lastseen')
        client.pop('status')
        now = datetime.now()
        lastbackup_elapsed = (
            now - datetime.fromtimestamp(last_backup_file)).total_seconds()
        lastbackup_image_elapsed = (
            now - datetime.fromtimestamp(last_backup_image)).total_seconds()
        print("urbackup,{} "
              "lastbackup={},lastbackup_image={},status={},"
              "lastbackup_elapsed={},lastbackup_image_elapsed={}".format(
                  ",".join([
                      "{}={}".format(k, v) for k, v in client.items()
                      if v != ''
                  ]), last_backup_file, last_backup_image, status,
                  lastbackup_elapsed, lastbackup_image_elapsed))
Ejemplo n.º 3
0
import urbackup_api

server = urbackup_api.urbackup_server("http://127.0.0.1:55414/x", "admin",
                                      "foo")

for action in server.get_actions():
    a = action["action"]
    if a == server.action_full_file or a == server.action_resumed_full_file:
        print("Running full file backup: " + action["name"])

        print("Stopping...")
        server.stop_action(action)
Ejemplo n.º 4
0
                    metavar='<count>',
                    type=check_positive,
                    help='maximum age of file backup')
parser.add_argument('--maximagedays',
                    '-i',
                    metavar='<count>',
                    type=check_positive,
                    help='maximum age of image backup')
parser.add_argument(
    'address',
    metavar='http[s]://<hostname>:<port>',
    help='full address of the Urbackup webinterface, without trailing slash')
args = parser.parse_args()

try:
    server = urbackup_api.urbackup_server(args.address + "/x", args.user,
                                          args.password)
    clients = server.get_status()
    client_regex = args.client
    status, details, count = get_global_status(clients, client_regex)
    if status == BackupStatus.CRITICAL:
        print("%i/%i OK, %i WARNING, %i CRITICAL" %
              (status[BackupStatus.OK], status["all"],
               status[BackupStatus.WARNING], status[BackupStatus.CRITICAL]))
        print(details)
        sys.exit(2)
    elif status == BackupStatus.WARNING:
        print("%i/%i OK, %i WARNING" % (status[BackupStatus.OK], status["all"],
                                        status[BackupStatus.WARNING]))
        print(details)
        sys.exit(1)
    elif status == BackupStatus.OK:
Ejemplo n.º 5
0
                    help='show agent version')
parser.add_argument('--host', '-ho', action="append", help='host name or IP')
parser.add_argument('--user',
                    '-u',
                    action="append",
                    help='User name for Urbackup server')
parser.add_argument('--password',
                    '-p',
                    action="append",
                    help='user password for Urbackup server')
args = parser.parse_args()

if args.host or args.user or args.password:
    try:
        server = urbackup_api.urbackup_server(
            "http://" + args.host[0] + ":55414/x", args.user[0],
            args.password[0])
        clients = server.get_status()
        for client in clients:
            GlobalStatus.append(Statuscheck(client))
            Globelstat = set(GlobalStatus)
        while True:
            if "Critical" in Globelstat:
                #print(Globelstat)
                print("CRITICAL: There are " + str(Perfdata_CRITICAL) +
                      " Backups in state CRITICAL \n\t-> OK:" +
                      str(Perfdata_OK) + " WARNING:" + str(Perfdata_WARNING) +
                      " CRITICAL:" + str(Perfdata_CRITICAL) + "\n")
                exitCode = 2
                break
            elif "Warning" in Globelstat:
Ejemplo n.º 6
0
                    action="append",
                    help='User name for Urbackup server')
parser.add_argument('--password',
                    '-p',
                    action="append",
                    help='user password for Urbackup server')
parser.add_argument('--critical', '-c', action="append", help='critical days')
parser.add_argument('--warning', '-w', action="append", help='warning days')
args = parser.parse_args()

if args.host and args.user and args.password and args.critical and args.warning:
    try:
        # server = urbackup_api.urbackup_server("http://"+ args.host[0] +":55414/x", args.user[0], args.password[0])
        # TODO: make url as arg
        server = urbackup_api.urbackup_server(
            "https://" + args.host[0] + "/urbackup/x", args.user[0],
            args.password[0])
        returnstatus = 0
        clients = server.get_status()
        # Debug:
        # print(clients)
        for client in clients:
            GlobalStatus.append(Statuscheck(client))
            Globalstat = set(GlobalStatus)
        from collections import Counter
        while True:
            if "CRITICAL" in Globalstat:
                #print(Globalstat)
                print("CRITICAL -",
                      Counter(GlobalStatus)['CRITICAL'], "/",
                      Counter(GlobalStatus)['WARNING'], "/",