This commit is contained in:
Einar Forselv 2019-12-05 11:09:36 +01:00
parent 0a9e5edfe4
commit 6f06d25db5
7 changed files with 12 additions and 12 deletions

View File

@ -2,7 +2,6 @@ import logging
from restic_compose_backup.alerts.smtp import SMTPAlert from restic_compose_backup.alerts.smtp import SMTPAlert
from restic_compose_backup.alerts.discord import DiscordWebhookAlert from restic_compose_backup.alerts.discord import DiscordWebhookAlert
from restic_compose_backup.config import Config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -37,7 +36,7 @@ def configured_alert_types():
for cls in BACKENDS: for cls in BACKENDS:
instance = cls.create_from_env() instance = cls.create_from_env()
logger.debug("Alert backend '%s' configured: %s", cls.name, instance != None) logger.debug("Alert backend '%s' configured: %s", cls.name, instance is not None)
if instance: if instance:
entires.append(instance) entires.append(instance)

View File

@ -1,6 +1,5 @@
import os import os
import logging import logging
from urllib.parse import urlparse
import requests import requests
from restic_compose_backup.alerts.base import BaseAlert from restic_compose_backup.alerts.base import BaseAlert
@ -41,6 +40,6 @@ class DiscordWebhookAlert(BaseAlert):
} }
response = requests.post(self.url, params={'wait': True}, json=data) response = requests.post(self.url, params={'wait': True}, json=data)
if response.status_code not in self.success_codes: if response.status_code not in self.success_codes:
log.error("Discord webhook failed: %s: %s", response.status_code, response.content) logger.error("Discord webhook failed: %s: %s", response.status_code, response.content)
else: else:
logger.info('Discord webhook successful') logger.info('Discord webhook successful')

View File

@ -1,5 +1,4 @@
import argparse import argparse
import pprint
import logging import logging
from restic_compose_backup import ( from restic_compose_backup import (
@ -63,7 +62,8 @@ def status(config, containers):
ping = instance.ping() ping = instance.ping()
logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0) logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0)
if ping != 0: if ping != 0:
logger.error("Database '%s' in service %s cannot be reached", instance.container_type, container.service_name) logger.error("Database '%s' in service %s cannot be reached",
instance.container_type, container.service_name)
if len(backup_containers) == 0: if len(backup_containers) == 0:
logger.info("No containers in the project has 'restic-compose-backup.enabled' label") logger.info("No containers in the project has 'restic-compose-backup.enabled' label")
@ -185,6 +185,7 @@ def cleanup(config, containers):
prune_result = restic.prune(config.repository) prune_result = restic.prune(config.repository)
return forget_result == 0 and prune_result == 0 return forget_result == 0 and prune_result == 0
def snapshots(config, containers): def snapshots(config, containers):
"""Display restic snapshots""" """Display restic snapshots"""
stdout, stderr = restic.snapshots(config.repository, last=True) stdout, stderr = restic.snapshots(config.repository, last=True)

View File

@ -6,7 +6,7 @@ logger = logging.getLogger(__name__)
def test(): def test():
return run_command(['ls', '/volumes']) return run(['ls', '/volumes'])
def ping_mysql(host, port, username) -> int: def ping_mysql(host, port, username) -> int:
@ -23,7 +23,7 @@ def ping_mysql(host, port, username) -> int:
]) ])
def ping_mariadb(host, port, username): #, password) -> int: def ping_mariadb(host, port, username) -> int:
"""Check if the mariadb is up and can be reached""" """Check if the mariadb is up and can be reached"""
return run([ return run([
'mysqladmin', 'mysqladmin',

View File

@ -13,6 +13,7 @@ LOG_LEVELS = {
'error': logging.ERROR, 'error': logging.ERROR,
} }
def setup(level: str = 'warning'): def setup(level: str = 'warning'):
"""Set up logging""" """Set up logging"""
level = level or "" level = level or ""