reworked the way that the iniparser works
This commit is contained in:
parent
fbc8488b07
commit
0656e2f06d
2 changed files with 70 additions and 185 deletions
|
@ -120,7 +120,7 @@ if __name__ == "__main__":
|
|||
schedule.every(server.get_missing_run_seconds).seconds.do(threaded, SICKCHILL.get_missing)
|
||||
|
||||
if CONFIG.ciscoasa_enabled:
|
||||
for firewall in CONFIG.ciscoasa_firewalls:
|
||||
for firewall in CONFIG.ciscoasa_servers:
|
||||
ASA = CiscoAPI(firewall, DBMANAGER)
|
||||
schedule.every(firewall.get_bandwidth_run_seconds).seconds.do(threaded, ASA.get_bandwidth)
|
||||
|
||||
|
|
|
@ -14,28 +14,14 @@ class INIParser(object):
|
|||
self.config = ConfigParser(interpolation=None)
|
||||
self.data_folder = data_folder
|
||||
|
||||
self.services = ['sonarr', 'radarr', 'ombi', 'tautulli', 'sickchill', 'ciscoasa']
|
||||
for service in self.services:
|
||||
setattr(self, f'{service}_servers', [])
|
||||
|
||||
self.logger = getLogger()
|
||||
|
||||
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.sickchill_enabled = False
|
||||
self.sickchill_servers = []
|
||||
|
||||
self.ciscoasa_enabled = False
|
||||
self.ciscoasa_firewalls = []
|
||||
|
||||
self.parse_opts()
|
||||
|
||||
self.filtered_strings = None
|
||||
|
@ -45,7 +31,7 @@ class INIParser(object):
|
|||
for k in section if k in BlacklistFilter.blacklisted_strings]
|
||||
self.filtered_strings = list(filter(None, filtered_strings))
|
||||
# Added matching for domains that use /locations. ConnectionPool ignores the location in logs
|
||||
domains_only = list([ string.split('/')[0] for string in filtered_strings if '/' in string ])
|
||||
domains_only = [string.split('/')[0] for string in filtered_strings if '/' in string]
|
||||
self.filtered_strings.extend(domains_only)
|
||||
|
||||
for handler in self.logger.handlers:
|
||||
|
@ -117,204 +103,103 @@ class INIParser(object):
|
|||
|
||||
self.influx_server = InfluxServer(url, port, username, password)
|
||||
|
||||
# Parse Sonarr options
|
||||
self.sonarr_enabled = self.enable_check('sonarr_server_ids')
|
||||
# Check for all enabled services
|
||||
for service in self.services:
|
||||
setattr(self, f'{service}_enabled', self.enable_check(f'{service}_server_ids'))
|
||||
service_enabled = getattr(self, f'{service}_enabled')
|
||||
|
||||
if self.sonarr_enabled:
|
||||
for server_id in self.sonarr_enabled:
|
||||
section = 'sonarr-' + str(server_id)
|
||||
try:
|
||||
url = self.url_check(self.config.get(section, 'url'))
|
||||
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'))
|
||||
|
||||
apikey = self.config.get(section, 'apikey')
|
||||
apikey = None
|
||||
if section != 'ciscoasa':
|
||||
apikey = self.config.get(section, 'apikey')
|
||||
|
||||
scheme = 'https://' if self.config.getboolean(section, 'ssl') else 'http://'
|
||||
scheme = 'https://' if self.config.getboolean(section, 'ssl') else 'http://'
|
||||
|
||||
verify_ssl = self.config.getboolean(section, 'verify_ssl')
|
||||
verify_ssl = self.config.getboolean(section, 'verify_ssl')
|
||||
|
||||
if scheme != 'https://':
|
||||
verify_ssl = False
|
||||
if scheme != 'https://':
|
||||
verify_ssl = False
|
||||
|
||||
queue = self.config.getboolean(section, 'queue')
|
||||
if service == 'sonarr':
|
||||
queue = self.config.getboolean(section, 'queue')
|
||||
|
||||
missing_days = self.config.getint(section, 'missing_days')
|
||||
missing_days = self.config.getint(section, 'missing_days')
|
||||
|
||||
future_days = self.config.getint(section, 'future_days')
|
||||
future_days = self.config.getint(section, 'future_days')
|
||||
|
||||
missing_days_run_seconds = self.config.getint(section, 'missing_days_run_seconds')
|
||||
missing_days_run_seconds = self.config.getint(section, 'missing_days_run_seconds')
|
||||
|
||||
future_days_run_seconds = self.config.getint(section, 'future_days_run_seconds')
|
||||
future_days_run_seconds = self.config.getint(section, 'future_days_run_seconds')
|
||||
|
||||
queue_run_seconds = self.config.getint(section, 'queue_run_seconds')
|
||||
queue_run_seconds = self.config.getint(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)
|
||||
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)
|
||||
except NoOptionError as e:
|
||||
self.sonarr_enabled = False
|
||||
self.logger.error(
|
||||
'%s disabled. Error: %s', section, e)
|
||||
if service == 'radarr':
|
||||
queue = self.config.getboolean(section, 'queue')
|
||||
|
||||
# Parse Radarr options
|
||||
self.radarr_enabled = self.enable_check('radarr_server_ids')
|
||||
queue_run_seconds = self.config.getint(section, 'queue_run_seconds')
|
||||
|
||||
if self.radarr_enabled:
|
||||
for server_id in self.radarr_enabled:
|
||||
section = 'radarr-' + str(server_id)
|
||||
try:
|
||||
url = self.url_check(self.config.get(section, 'url'))
|
||||
get_missing = self.config.getboolean(section, 'get_missing')
|
||||
|
||||
apikey = self.config.get(section, 'apikey')
|
||||
get_missing_run_seconds = self.config.getint(section, 'get_missing_run_seconds')
|
||||
|
||||
scheme = 'https://' if self.config.getboolean(section, 'ssl') else 'http://'
|
||||
server = RadarrServer(server_id, scheme + url, apikey, verify_ssl, queue, queue_run_seconds,
|
||||
get_missing, get_missing_run_seconds)
|
||||
|
||||
verify_ssl = self.config.getboolean(section, 'verify_ssl')
|
||||
if service == 'tautulli':
|
||||
fallback_ip = self.config.get(section, 'fallback_ip')
|
||||
|
||||
if scheme != 'https://':
|
||||
verify_ssl = False
|
||||
get_activity = self.config.getboolean(section, 'get_activity')
|
||||
|
||||
queue = self.config.getboolean(section, 'queue')
|
||||
get_activity_run_seconds = self.config.getint(section, 'get_activity_run_seconds')
|
||||
|
||||
queue_run_seconds = self.config.getint(section, 'queue_run_seconds')
|
||||
server = TautulliServer(server_id, scheme + url, fallback_ip, apikey, verify_ssl,
|
||||
get_activity, get_activity_run_seconds)
|
||||
|
||||
get_missing = self.config.getboolean(section, 'get_missing')
|
||||
if service == 'ombi':
|
||||
request_type_counts = self.config.getboolean(section, 'get_request_type_counts')
|
||||
|
||||
get_missing_run_seconds = self.config.getint(section, 'get_missing_run_seconds')
|
||||
request_type_run_seconds = self.config.getint(section, 'request_type_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)
|
||||
except NoOptionError as e:
|
||||
self.radarr_enabled = False
|
||||
self.logger.error(
|
||||
'%s disabled. Error: %s', section, e)
|
||||
request_total_counts = self.config.getboolean(section, 'get_request_total_counts')
|
||||
|
||||
# Parse Tautulli options
|
||||
self.tautulli_enabled = self.enable_check('tautulli_server_ids')
|
||||
request_total_run_seconds = self.config.getint(section, 'request_total_run_seconds')
|
||||
|
||||
if self.tautulli_enabled:
|
||||
for server_id in self.tautulli_enabled:
|
||||
section = 'tautulli-' + str(server_id)
|
||||
try:
|
||||
url = self.url_check(self.config.get(section, 'url'))
|
||||
server = OmbiServer(server_id, scheme + url, apikey, verify_ssl, request_type_counts,
|
||||
request_type_run_seconds, request_total_counts,
|
||||
request_total_run_seconds)
|
||||
|
||||
fallback_ip = self.config.get(section, 'fallback_ip')
|
||||
if service == 'sickchill':
|
||||
get_missing = self.config.getboolean(section, 'get_missing')
|
||||
|
||||
apikey = self.config.get(section, 'apikey')
|
||||
get_missing_run_seconds = self.config.getint(section, 'get_missing_run_seconds')
|
||||
|
||||
scheme = 'https://' if self.config.getboolean(section, 'ssl') else 'http://'
|
||||
server = SickChillServer(server_id, scheme + url, apikey, verify_ssl,
|
||||
get_missing, get_missing_run_seconds)
|
||||
|
||||
verify_ssl = self.config.getboolean(section, 'verify_ssl')
|
||||
if service == 'ciscoasa':
|
||||
username = self.config.get(section, 'username')
|
||||
|
||||
if scheme != 'https://':
|
||||
verify_ssl = False
|
||||
password = self.config.get(section, 'password')
|
||||
|
||||
get_activity = self.config.getboolean(section, 'get_activity')
|
||||
outside_interface = self.config.get(section, 'outside_interface')
|
||||
|
||||
get_activity_run_seconds = self.config.getint(section, 'get_activity_run_seconds')
|
||||
get_bandwidth_run_seconds = self.config.getint(section, 'get_bandwidth_run_seconds')
|
||||
|
||||
server = TautulliServer(server_id, scheme + url, fallback_ip, apikey, verify_ssl, get_activity,
|
||||
get_activity_run_seconds)
|
||||
self.tautulli_servers.append(server)
|
||||
except NoOptionError as e:
|
||||
self.tautulli_enabled = False
|
||||
self.logger.error(
|
||||
'%s disabled. Error: %s', section, e)
|
||||
server = CiscoASAFirewall(server_id, scheme + url, username, password, outside_interface,
|
||||
verify_ssl, get_bandwidth_run_seconds)
|
||||
|
||||
# Parse Ombi options
|
||||
self.ombi_enabled = self.enable_check('ombi_server_ids')
|
||||
getattr(self, f'{service}_servers').append(server)
|
||||
|
||||
if self.ombi_enabled:
|
||||
for server_id in self.ombi_enabled:
|
||||
section = 'ombi-' + str(server_id)
|
||||
try:
|
||||
url = self.url_check(self.config.get(section, 'url'))
|
||||
|
||||
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
|
||||
|
||||
request_type_counts = self.config.getboolean(section, 'get_request_type_counts')
|
||||
|
||||
request_type_run_seconds = self.config.getint(section, 'request_type_run_seconds')
|
||||
|
||||
request_total_counts = self.config.getboolean(section, 'get_request_total_counts')
|
||||
|
||||
request_total_run_seconds = self.config.getint(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)
|
||||
except NoOptionError as e:
|
||||
self.ombi_enabled = False
|
||||
self.logger.error(
|
||||
'%s disabled. Error: %s', section, e)
|
||||
|
||||
# Parse SickChill options
|
||||
self.sickchill_enabled = self.enable_check('sickchill_server_ids')
|
||||
|
||||
if self.sickchill_enabled:
|
||||
for server_id in self.sickchill_enabled:
|
||||
section = 'sickchill-' + str(server_id)
|
||||
try:
|
||||
url = self.url_check(self.config.get(section, 'url'))
|
||||
|
||||
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
|
||||
|
||||
get_missing = self.config.getboolean(section, 'get_missing')
|
||||
|
||||
get_missing_run_seconds = self.config.getint(section, 'get_missing_run_seconds')
|
||||
|
||||
server = SickChillServer(server_id, scheme + url, apikey, verify_ssl,
|
||||
get_missing, get_missing_run_seconds)
|
||||
self.sickchill_servers.append(server)
|
||||
except NoOptionError as e:
|
||||
self.sickchill_enabled = False
|
||||
self.logger.error(
|
||||
'%s disabled. Error: %s', section, e)
|
||||
|
||||
# Parse ASA opts
|
||||
self.ciscoasa_enabled = self.enable_check('ciscoasa_firewall_ids')
|
||||
|
||||
if self.ciscoasa_enabled:
|
||||
for firewall_id in self.ciscoasa_enabled:
|
||||
section = 'ciscoasa-' + str(firewall_id)
|
||||
try:
|
||||
url = self.url_check(self.config.get(section, 'url'))
|
||||
|
||||
username = self.config.get(section, 'username')
|
||||
|
||||
password = self.config.get(section, 'password')
|
||||
|
||||
scheme = 'https://' if self.config.getboolean(section, 'ssl') else 'http://'
|
||||
|
||||
verify_ssl = self.config.getboolean(section, 'verify_ssl')
|
||||
|
||||
if scheme != 'https://':
|
||||
verify_ssl = False
|
||||
|
||||
outside_interface = self.config.get(section, 'outside_interface')
|
||||
|
||||
get_bandwidth_run_seconds = self.config.getint(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)
|
||||
except NoOptionError as e:
|
||||
self.ciscoasa_enabled = False
|
||||
self.logger.error(
|
||||
'%s disabled. Error: %s', section, e)
|
||||
except NoOptionError as e:
|
||||
setattr(self, f'{service}_enabled', False)
|
||||
self.logger.error('%s disabled. Error: %s', section, e)
|
||||
|
|
Loading…
Reference in a new issue