Exemplo n.º 1
0
    def __init__(self, data_folder):
        self.config = None
        self.data_folder = data_folder
        self.filtered_strings = None
        self.services = ['sonarr', 'radarr', 'lidarr', 'ombi', 'tautulli', 'sickchill', 'unifi']

        self.logger = getLogger()
        self.influx_server = InfluxServer()

        try:
            self.parse_opts(read_file=True)
        except NoSectionError as e:
            self.logger.error('Missing section in (varken.ini): %s', e)
            self.rectify_ini()
Exemplo n.º 2
0
    def __init__(self, data_folder):
        self.config = configparser.ConfigParser(interpolation=None)
        self.data_folder = data_folder

        self.influx_server = InfluxServer()

        self.sonarr_enabled = False
        self.sonarr_servers = []

        self.radarr_enabled = False
        self.radarr_servers = []

        self.ombi_enabled = False
        self.ombi_servers = []

        self.tautulli_enabled = False
        self.tautulli_servers = []

        self.ciscoasa_enabled = False
        self.ciscoasa_firewalls = []

        self.parse_opts()
Exemplo n.º 3
0
    def parse_opts(self, read_file=False):
        for service in self.services:
            setattr(self, f'{service}_servers', [])

        if read_file:
            self.config = self.read_file('varken.ini')
            self.config_blacklist()
        # Parse InfluxDB options
        try:
            url = self.url_check(env.get('VRKN_INFLUXDB_URL',
                                         self.config.get('influxdb', 'url')),
                                 include_port=False,
                                 section='influxdb')
            port = int(
                env.get('VRKN_INFLUXDB_PORT',
                        self.config.getint('influxdb', 'port')))
            ssl = boolcheck(
                env.get('VRKN_INFLUXDB_SSL',
                        self.config.get('influxdb', 'ssl')))
            verify_ssl = boolcheck(
                env.get('VRKN_INFLUXDB_VERIFY_SSL',
                        self.config.get('influxdb', 'verify_ssl')))

            username = env.get('VRKN_INFLUXDB_USERNAME',
                               self.config.get('influxdb', 'username'))
            password = env.get('VRKN_INFLUXDB_PASSWORD',
                               self.config.get('influxdb', 'password'))
        except NoOptionError as e:
            self.logger.error('Missing key in %s. Error: %s', "influxdb", e)
            self.rectify_ini()
            return

        self.influx_server = InfluxServer(url=url,
                                          port=port,
                                          username=username,
                                          password=password,
                                          ssl=ssl,
                                          verify_ssl=verify_ssl)

        # Check for all enabled services
        for service in self.services:
            try:
                setattr(self, f'{service}_enabled',
                        self.enable_check(f'{service}_server_ids'))
            except NoOptionError as e:
                self.logger.error('Missing global %s. Error: %s',
                                  f'{service}_server_ids', e)
                self.rectify_ini()
                return
            service_enabled = getattr(self, f'{service}_enabled')

            if service_enabled:
                for server_id in service_enabled:
                    server = None
                    section = f"{service}-{server_id}"
                    envsection = f"{service}_{server_id}".upper()
                    try:
                        url = self.url_check(env.get(
                            f'VRKN_{envsection}_URL',
                            self.config.get(section, 'url')),
                                             section=section)

                        apikey = None
                        if service != 'unifi':
                            apikey = env.get(
                                f'VRKN_{envsection}_APIKEY',
                                self.config.get(section, 'apikey'))
                        ssl_scheme = boolcheck(
                            env.get(f'VRKN_{envsection}_SSL',
                                    self.config.get(section, 'ssl')))
                        scheme = 'https://' if ssl_scheme else 'http://'
                        verify_ssl = boolcheck(
                            env.get(f'VRKN_{envsection}_VERIFY_SSL',
                                    self.config.get(section, 'verify_ssl')))

                        if scheme != 'https://':
                            verify_ssl = False

                        if service in ['sonarr', 'radarr', 'lidarr']:
                            queue = boolcheck(
                                env.get(f'VRKN_{envsection}_QUEUE',
                                        self.config.get(section, 'queue')))
                            queue_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_QUEUE_RUN_SECONDS',
                                    self.config.getint(section,
                                                       'queue_run_seconds')))

                        if service in ['sonarr', 'lidarr']:
                            missing_days = int(
                                env.get(
                                    f'VRKN_{envsection}_MISSING_DAYS',
                                    self.config.getint(section,
                                                       'missing_days')))
                            future_days = int(
                                env.get(
                                    f'VRKN_{envsection}_FUTURE_DAYS',
                                    self.config.getint(section,
                                                       'future_days')))

                            missing_days_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_MISSING_DAYS_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'missing_days_run_seconds')))

                            future_days_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_FUTURE_DAYS_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'future_days_run_seconds')))

                            server = SonarrServer(
                                id=server_id,
                                url=scheme + url,
                                api_key=apikey,
                                verify_ssl=verify_ssl,
                                missing_days=missing_days,
                                future_days=future_days,
                                missing_days_run_seconds=
                                missing_days_run_seconds,
                                future_days_run_seconds=future_days_run_seconds,
                                queue=queue,
                                queue_run_seconds=queue_run_seconds)

                        if service == 'radarr':
                            get_missing = boolcheck(
                                env.get(
                                    f'VRKN_{envsection}_GET_MISSING',
                                    self.config.get(section, 'get_missing')))
                            get_missing_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_GET_MISSING_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'get_missing_run_seconds')))

                            server = RadarrServer(
                                id=server_id,
                                url=scheme + url,
                                api_key=apikey,
                                verify_ssl=verify_ssl,
                                queue_run_seconds=queue_run_seconds,
                                get_missing=get_missing,
                                queue=queue,
                                get_missing_run_seconds=get_missing_run_seconds
                            )

                        if service == 'tautulli':
                            fallback_ip = env.get(
                                f'VRKN_{envsection}_FALLBACK_IP',
                                self.config.get(section, 'fallback_ip'))

                            get_stats = boolcheck(
                                env.get(f'VRKN_{envsection}_GET_STATS',
                                        self.config.get(section, 'get_stats')))

                            get_activity = boolcheck(
                                env.get(
                                    f'VRKN_{envsection}_GET_ACTIVITY',
                                    self.config.get(section, 'get_activity')))

                            get_activity_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_GET_ACTIVITY_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'get_activity_run_seconds')))

                            get_stats_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_GET_STATS_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'get_stats_run_seconds')))

                            invalid_wan_ip = rfc1918_ip_check(fallback_ip)

                            if invalid_wan_ip:
                                self.logger.error(
                                    'Invalid fallback_ip [%s] set for %s-%s!',
                                    fallback_ip, service, server_id)
                                exit(1)

                            maxmind_license_key = env.get(
                                'VRKN_GLOBAL_MAXMIND_LICENSE_KEY',
                                self.config.get('global',
                                                'maxmind_license_key'))

                            server = TautulliServer(
                                id=server_id,
                                url=scheme + url,
                                api_key=apikey,
                                verify_ssl=verify_ssl,
                                get_activity=get_activity,
                                fallback_ip=fallback_ip,
                                get_stats=get_stats,
                                get_activity_run_seconds=
                                get_activity_run_seconds,
                                get_stats_run_seconds=get_stats_run_seconds,
                                maxmind_license_key=maxmind_license_key)

                        if service == 'ombi':
                            issue_status_counts = boolcheck(
                                env.get(
                                    f'VRKN_{envsection}_GET_ISSUE_STATUS_COUNTS',
                                    self.config.get(
                                        section, 'get_issue_status_counts')))
                            request_type_counts = boolcheck(
                                env.get(
                                    f'VRKN_{envsection}_GET_REQUEST_TYPE_COUNTS',
                                    self.config.get(
                                        section, 'get_request_type_counts')))
                            request_total_counts = boolcheck(
                                env.get(
                                    f'VRKN_{envsection}_GET_REQUEST_TOTAL_COUNTS',
                                    self.config.get(
                                        section, 'get_request_total_counts')))

                            issue_status_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_ISSUE_STATUS_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'issue_status_run_seconds')))
                            request_type_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_REQUEST_TYPE_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'request_type_run_seconds')))
                            request_total_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_REQUEST_TOTAL_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'request_total_run_seconds')))

                            server = OmbiServer(
                                id=server_id,
                                url=scheme + url,
                                api_key=apikey,
                                verify_ssl=verify_ssl,
                                request_type_counts=request_type_counts,
                                request_type_run_seconds=
                                request_type_run_seconds,
                                request_total_counts=request_total_counts,
                                request_total_run_seconds=
                                request_total_run_seconds,
                                issue_status_counts=issue_status_counts,
                                issue_status_run_seconds=
                                issue_status_run_seconds)

                        if service == 'sickchill':
                            get_missing = boolcheck(
                                env.get(
                                    f'VRKN_{envsection}_GET_MISSING',
                                    self.config.get(section, 'get_missing')))
                            get_missing_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_GET_MISSING_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'get_missing_run_seconds')))

                            server = SickChillServer(
                                id=server_id,
                                url=scheme + url,
                                api_key=apikey,
                                verify_ssl=verify_ssl,
                                get_missing=get_missing,
                                get_missing_run_seconds=get_missing_run_seconds
                            )

                        if service == 'unifi':
                            username = env.get(
                                f'VRKN_{envsection}_USERNAME',
                                self.config.get(section, 'username'))
                            password = env.get(
                                f'VRKN_{envsection}_PASSWORD',
                                self.config.get(section, 'password'))
                            site = env.get(f'VRKN_{envsection}_SITE',
                                           self.config.get(section,
                                                           'site')).lower()
                            usg_name = env.get(
                                f'VRKN_{envsection}_USG_NAME',
                                self.config.get(section, 'usg_name'))
                            get_usg_stats_run_seconds = int(
                                env.get(
                                    f'VRKN_{envsection}_GET_USG_STATS_RUN_SECONDS',
                                    self.config.getint(
                                        section, 'get_usg_stats_run_seconds')))

                            server = UniFiServer(id=server_id,
                                                 url=scheme + url,
                                                 verify_ssl=verify_ssl,
                                                 site=site,
                                                 username=username,
                                                 password=password,
                                                 usg_name=usg_name,
                                                 get_usg_stats_run_seconds=
                                                 get_usg_stats_run_seconds)

                        getattr(self, f'{service}_servers').append(server)
                    except NoOptionError as e:
                        self.logger.error('Missing key in %s. Error: %s',
                                          section, e)
                        self.rectify_ini()
                        return
                    except ValueError as e:
                        self.logger.error(
                            "Invalid configuration value in %s. Error: %s",
                            section, e)
Exemplo n.º 4
0
    def parse_opts(self):
        self.read_file()
        # Parse InfluxDB options
        url = self.config.get('influxdb', 'url')
        port = self.config.getint('influxdb', 'port')
        username = self.config.get('influxdb', 'username')
        password = self.config.get('influxdb', 'password')

        self.influx_server = InfluxServer(url, port, username, password)

        # Parse Sonarr options
        self.sonarr_enabled = self.enable_check('sonarr_server_ids')

        if self.sonarr_enabled:
            sids = self.config.get('global',
                                   'sonarr_server_ids').strip(' ').split(',')

            for server_id in sids:
                sonarr_section = 'sonarr-' + server_id
                url = self.config.get(sonarr_section, 'url')
                apikey = self.config.get(sonarr_section, 'apikey')
                scheme = 'https://' if self.config.getboolean(
                    sonarr_section, 'ssl') else 'http://'
                verify_ssl = self.config.getboolean(sonarr_section,
                                                    'verify_ssl')
                if scheme != 'https://':
                    verify_ssl = False
                queue = self.config.getboolean(sonarr_section, 'queue')
                missing_days = self.config.getint(sonarr_section,
                                                  'missing_days')
                future_days = self.config.getint(sonarr_section, 'future_days')
                missing_days_run_seconds = self.config.getint(
                    sonarr_section, 'missing_days_run_seconds')
                future_days_run_seconds = self.config.getint(
                    sonarr_section, 'future_days_run_seconds')
                queue_run_seconds = self.config.getint(sonarr_section,
                                                       'queue_run_seconds')

                server = SonarrServer(server_id, scheme + url, apikey,
                                      verify_ssl, missing_days,
                                      missing_days_run_seconds, future_days,
                                      future_days_run_seconds, queue,
                                      queue_run_seconds)
                self.sonarr_servers.append(server)

        # Parse Radarr options
        self.radarr_enabled = self.enable_check('radarr_server_ids')

        if self.radarr_enabled:
            sids = self.config.get('global',
                                   'radarr_server_ids').strip(' ').split(',')

            for server_id in sids:
                radarr_section = 'radarr-' + server_id
                url = self.config.get(radarr_section, 'url')
                apikey = self.config.get(radarr_section, 'apikey')
                scheme = 'https://' if self.config.getboolean(
                    radarr_section, 'ssl') else 'http://'
                verify_ssl = self.config.getboolean(radarr_section,
                                                    'verify_ssl')
                if scheme != 'https://':
                    verify_ssl = False
                queue = self.config.getboolean(radarr_section, 'queue')
                queue_run_seconds = self.config.getint(radarr_section,
                                                       'queue_run_seconds')
                get_missing = self.config.getboolean(radarr_section,
                                                     'get_missing')
                get_missing_run_seconds = self.config.getint(
                    radarr_section, 'get_missing_run_seconds')

                server = RadarrServer(server_id, scheme + url, apikey,
                                      verify_ssl, queue, queue_run_seconds,
                                      get_missing, get_missing_run_seconds)
                self.radarr_servers.append(server)

        # Parse Tautulli options
        self.tautulli_enabled = self.enable_check('tautulli_server_ids')

        if self.tautulli_enabled:
            sids = self.config.get('global',
                                   'tautulli_server_ids').strip(' ').split(',')

            for server_id in sids:
                tautulli_section = 'tautulli-' + server_id
                url = self.config.get(tautulli_section, 'url')
                fallback_ip = self.config.get(tautulli_section, 'fallback_ip')
                apikey = self.config.get(tautulli_section, 'apikey')
                scheme = 'https://' if self.config.getboolean(
                    tautulli_section, 'ssl') else 'http://'
                verify_ssl = self.config.getboolean(tautulli_section,
                                                    'verify_ssl')
                if scheme != 'https://':
                    verify_ssl = False
                get_activity = self.config.getboolean(tautulli_section,
                                                      'get_activity')
                get_activity_run_seconds = self.config.getint(
                    tautulli_section, 'get_activity_run_seconds')

                server = TautulliServer(server_id, scheme + url, fallback_ip,
                                        apikey, verify_ssl, get_activity,
                                        get_activity_run_seconds)
                self.tautulli_servers.append(server)

        # Parse Ombi options
        self.ombi_enabled = self.enable_check('ombi_server_ids')

        if self.ombi_enabled:
            sids = self.config.get('global',
                                   'ombi_server_ids').strip(' ').split(',')
            for server_id in sids:
                ombi_section = 'ombi-' + server_id
                url = self.config.get(ombi_section, 'url')
                apikey = self.config.get(ombi_section, 'apikey')
                scheme = 'https://' if self.config.getboolean(
                    ombi_section, 'ssl') else 'http://'
                verify_ssl = self.config.getboolean(ombi_section, 'verify_ssl')
                if scheme != 'https://':
                    verify_ssl = False
                request_type_counts = self.config.getboolean(
                    ombi_section, 'get_request_type_counts')
                request_type_run_seconds = self.config.getint(
                    ombi_section, 'request_type_run_seconds')
                request_total_counts = self.config.getboolean(
                    ombi_section, 'get_request_total_counts')
                request_total_run_seconds = self.config.getint(
                    ombi_section, 'request_total_run_seconds')

                server = OmbiServer(server_id, scheme + url, apikey,
                                    verify_ssl, request_type_counts,
                                    request_type_run_seconds,
                                    request_total_counts,
                                    request_total_run_seconds)
                self.ombi_servers.append(server)

        # Parse ASA opts
        self.ciscoasa_enabled = self.enable_check('ciscoasa_firewall_ids')

        if self.ciscoasa_enabled:
            fids = self.config.get(
                'global', 'ciscoasa_firewall_ids').strip(' ').split(',')
            for firewall_id in fids:
                ciscoasa_section = 'ciscoasa-' + firewall_id
                url = self.config.get(ciscoasa_section, 'url')
                username = self.config.get(ciscoasa_section, 'username')
                password = self.config.get(ciscoasa_section, 'password')
                scheme = 'https://' if self.config.getboolean(
                    ciscoasa_section, 'ssl') else 'http://'
                verify_ssl = self.config.getboolean(ciscoasa_section,
                                                    'verify_ssl')
                if scheme != 'https://':
                    verify_ssl = False
                outside_interface = self.config.get(ciscoasa_section,
                                                    'outside_interface')
                get_bandwidth_run_seconds = self.config.getint(
                    ciscoasa_section, 'get_bandwidth_run_seconds')

                firewall = CiscoASAFirewall(firewall_id, scheme + url,
                                            username, password,
                                            outside_interface, verify_ssl,
                                            get_bandwidth_run_seconds)
                self.ciscoasa_firewalls.append(firewall)
Exemplo n.º 5
0
    def parse_opts(self, read_file=False):
        for service in self.services:
            setattr(self, f'{service}_servers', [])

        if read_file:
            self.config = self.read_file('varken.ini')
            self.config_blacklist()
        # Parse InfluxDB options
        try:
            url = self.url_check(self.config.get('influxdb', 'url'), include_port=False, section='influxdb')
            port = self.config.getint('influxdb', 'port')
            ssl = self.config.getboolean('influxdb', 'ssl')
            verify_ssl = self.config.getboolean('influxdb', 'verify_ssl')

            username = self.config.get('influxdb', 'username')
            password = self.config.get('influxdb', 'password')
        except NoOptionError as e:
            self.logger.error('Missing key in %s. Error: %s', "influxdb", e)
            self.rectify_ini()
            return

        self.influx_server = InfluxServer(url=url, port=port, username=username, password=password, ssl=ssl,
                                          verify_ssl=verify_ssl)

        # Check for all enabled services
        for service in self.services:
            try:
                setattr(self, f'{service}_enabled', self.enable_check(f'{service}_server_ids'))
            except NoOptionError as e:
                self.logger.error('Missing global %s. Error: %s', f'{service}_server_ids', e)
                self.rectify_ini()
                return
            service_enabled = getattr(self, f'{service}_enabled')

            if service_enabled:
                for server_id in service_enabled:
                    server = None
                    section = f"{service}-{server_id}"
                    try:
                        url = self.url_check(self.config.get(section, 'url'), section=section)

                        apikey = None
                        if service != 'unifi':
                            apikey = self.config.get(section, 'apikey')

                        scheme = 'https://' if self.config.getboolean(section, 'ssl') else 'http://'
                        verify_ssl = self.config.getboolean(section, 'verify_ssl')

                        if scheme != 'https://':
                            verify_ssl = False

                        if service in ['sonarr', 'radarr', 'lidarr']:
                            queue = self.config.getboolean(section, 'queue')
                            queue_run_seconds = self.config.getint(section, 'queue_run_seconds')

                        if service in ['sonarr', 'lidarr']:
                            missing_days = self.config.getint(section, 'missing_days')
                            future_days = self.config.getint(section, 'future_days')

                            missing_days_run_seconds = self.config.getint(section, 'missing_days_run_seconds')
                            future_days_run_seconds = self.config.getint(section, 'future_days_run_seconds')

                            server = SonarrServer(id=server_id, url=scheme + url, api_key=apikey, verify_ssl=verify_ssl,
                                                  missing_days=missing_days, future_days=future_days,
                                                  missing_days_run_seconds=missing_days_run_seconds,
                                                  future_days_run_seconds=future_days_run_seconds,
                                                  queue=queue, queue_run_seconds=queue_run_seconds)

                        if service == 'radarr':
                            get_missing = self.config.getboolean(section, 'get_missing')
                            get_missing_run_seconds = self.config.getint(section, 'get_missing_run_seconds')

                            server = RadarrServer(id=server_id, url=scheme + url, api_key=apikey, verify_ssl=verify_ssl,
                                                  queue_run_seconds=queue_run_seconds, get_missing=get_missing,
                                                  queue=queue, get_missing_run_seconds=get_missing_run_seconds)

                        if service == 'tautulli':
                            fallback_ip = self.config.get(section, 'fallback_ip')

                            get_stats = self.config.getboolean(section, 'get_stats')
                            get_activity = self.config.getboolean(section, 'get_activity')

                            get_activity_run_seconds = self.config.getint(section, 'get_activity_run_seconds')
                            get_stats_run_seconds = self.config.getint(section, 'get_stats_run_seconds')

                            invalid_wan_ip = rfc1918_ip_check(fallback_ip)

                            if invalid_wan_ip:
                                self.logger.error('Invalid fallback_ip [%s] set for %s-%s!', fallback_ip, service,
                                                  server_id)
                                exit(1)

                            server = TautulliServer(id=server_id, url=scheme + url, api_key=apikey,
                                                    verify_ssl=verify_ssl, get_activity=get_activity,
                                                    fallback_ip=fallback_ip, get_stats=get_stats,
                                                    get_activity_run_seconds=get_activity_run_seconds,
                                                    get_stats_run_seconds=get_stats_run_seconds)

                        if service == 'ombi':
                            issue_status_counts = self.config.getboolean(section, 'get_issue_status_counts')
                            request_type_counts = self.config.getboolean(section, 'get_request_type_counts')
                            request_total_counts = self.config.getboolean(section, 'get_request_total_counts')

                            issue_status_run_seconds = self.config.getint(section, 'issue_status_run_seconds')
                            request_type_run_seconds = self.config.getint(section, 'request_type_run_seconds')
                            request_total_run_seconds = self.config.getint(section, 'request_total_run_seconds')

                            server = OmbiServer(id=server_id, url=scheme + url, api_key=apikey, verify_ssl=verify_ssl,
                                                request_type_counts=request_type_counts,
                                                request_type_run_seconds=request_type_run_seconds,
                                                request_total_counts=request_total_counts,
                                                request_total_run_seconds=request_total_run_seconds,
                                                issue_status_counts=issue_status_counts,
                                                issue_status_run_seconds=issue_status_run_seconds)

                        if service == 'sickchill':
                            get_missing = self.config.getboolean(section, 'get_missing')
                            get_missing_run_seconds = self.config.getint(section, 'get_missing_run_seconds')

                            server = SickChillServer(id=server_id, url=scheme + url, api_key=apikey,
                                                     verify_ssl=verify_ssl, get_missing=get_missing,
                                                     get_missing_run_seconds=get_missing_run_seconds)

                        if service == 'unifi':
                            username = self.config.get(section, 'username')
                            password = self.config.get(section, 'password')
                            site = self.config.get(section, 'site').lower()
                            usg_name = self.config.get(section, 'usg_name')
                            get_usg_stats_run_seconds = self.config.getint(section, 'get_usg_stats_run_seconds')

                            server = UniFiServer(id=server_id, url=scheme + url, verify_ssl=verify_ssl, site=site,
                                                 username=username, password=password, usg_name=usg_name,
                                                 get_usg_stats_run_seconds=get_usg_stats_run_seconds)

                        getattr(self, f'{service}_servers').append(server)
                    except NoOptionError as e:
                        self.logger.error('Missing key in %s. Error: %s', section, e)
                        self.rectify_ini()
                        return