Skip to content

Commit 7a93126

Browse files
committed
Style fixes
1 parent e1702b3 commit 7a93126

File tree

4 files changed

+78
-52
lines changed

4 files changed

+78
-52
lines changed

LibreNMS/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import timeit
1010
from collections import deque
1111
from logging.handlers import RotatingFileHandler
12-
from math import ceil
1312
from queue import Queue
1413
from time import time
1514

15+
from math import ceil
16+
1617
from .command_runner import command_runner
1718
from .service import LogOutput
1819

@@ -211,7 +212,9 @@ def call_script(script, args=(), log_dest=None):
211212
kwargs["stderr"] = log_dest
212213
elif isinstance(log_dest, LogOutput):
213214
if log_dest is LogOutput.FILE:
214-
raise ValueError("For FILE mode, pass a file path string instead of LogOutput.FILE")
215+
raise ValueError(
216+
"For FILE mode, pass a file path string instead of LogOutput.FILE"
217+
)
215218

216219
elif log_dest is LogOutput.NONE:
217220
kwargs["stdout"] = subprocess.DEVNULL

LibreNMS/queuemanager.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,13 @@ def do_work(self, device_id, group):
447447
if self.lock(device_id, timeout=self.config.services.frequency):
448448
logger.info("Checking services on device {}".format(device_id))
449449

450-
output = "{}/dispatch_device_{}_services.log".format(
451-
self.config.logdir, device_id
452-
) if self.config.log_output == LibreNMS.LogOutput.FILE else self.config.log_output
450+
output = (
451+
"{}/dispatch_device_{}_services.log".format(
452+
self.config.logdir, device_id
453+
)
454+
if self.config.log_output == LibreNMS.LogOutput.FILE
455+
else self.config.log_output
456+
)
453457

454458
args = ("-d", "-h", device_id) if self.config.debug else ("-h", device_id)
455459
exit_code, output = LibreNMS.call_script("check-services.php", args, output)
@@ -493,7 +497,11 @@ def do_dispatch(self):
493497
def do_work(self, device_id, group):
494498
logger.info("Checking alerts")
495499

496-
output = "{}/dispatch_alerts.log".format(self.config.logdir) if self.config.log_output == LibreNMS.LogOutput.FILE else self.config.log_output
500+
output = (
501+
"{}/dispatch_alerts.log".format(self.config.logdir)
502+
if self.config.log_output == LibreNMS.LogOutput.FILE
503+
else self.config.log_output
504+
)
497505

498506
args = ("-d", "-f") if self.config.debug else ("-f",)
499507
exit_code, output = LibreNMS.call_script("alerts.php", args, output)
@@ -521,9 +529,11 @@ def do_work(self, device_id, group):
521529
if self.lock(device_id, timeout=self.config.poller.frequency):
522530
logger.info("Polling device {}".format(device_id))
523531

524-
output = "{}/dispatch_device_{}_poller.log".format(
525-
self.config.logdir, device_id
526-
) if self.config.log_output == LibreNMS.LogOutput.FILE else self.config.log_output
532+
output = (
533+
"{}/dispatch_device_{}_poller.log".format(self.config.logdir, device_id)
534+
if self.config.log_output == LibreNMS.LogOutput.FILE
535+
else self.config.log_output
536+
)
527537

528538
args = (
529539
("device:poll", device_id, "-vv")
@@ -585,9 +595,13 @@ def do_work(self, device_id, group):
585595
):
586596
logger.info("Discovering device {}".format(device_id))
587597

588-
output = "{}/dispatch_device_{}_discovery.log".format(
589-
self.config.logdir, device_id
590-
) if self.config.log_output == LibreNMS.LogOutput.FILE else self.config.log_output
598+
output = (
599+
"{}/dispatch_device_{}_discovery.log".format(
600+
self.config.logdir, device_id
601+
)
602+
if self.config.log_output == LibreNMS.LogOutput.FILE
603+
else self.config.log_output
604+
)
591605

592606
args = (
593607
("device:discover", device_id, "-vv")

LibreNMS/service.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class RedisConnectionError(Exception):
3939

4040
logger = logging.getLogger(__name__)
4141

42+
4243
class LogOutput(Enum):
4344
NONE = "none"
4445
STDOUT = "stdout"
@@ -255,9 +256,11 @@ def populate(self):
255256
self.redis_timeout = int(
256257
os.getenv(
257258
"REDIS_TIMEOUT",
258-
self.alerting.frequency
259-
if self.alerting.frequency != 0
260-
else self.redis_timeout,
259+
(
260+
self.alerting.frequency
261+
if self.alerting.frequency != 0
262+
else self.redis_timeout
263+
),
261264
)
262265
)
263266

@@ -522,15 +525,21 @@ def start(self):
522525
)
523526
logger.info(
524527
"Queue Workers: Discovery={} Poller={} Services={} Alerting={} Billing={} Ping={}".format(
525-
self.config.discovery.workers
526-
if self.config.discovery.enabled
527-
else "disabled",
528-
self.config.poller.workers
529-
if self.config.poller.enabled
530-
else "disabled",
531-
self.config.services.workers
532-
if self.config.services.enabled
533-
else "disabled",
528+
(
529+
self.config.discovery.workers
530+
if self.config.discovery.enabled
531+
else "disabled"
532+
),
533+
(
534+
self.config.poller.workers
535+
if self.config.poller.enabled
536+
else "disabled"
537+
),
538+
(
539+
self.config.services.workers
540+
if self.config.services.enabled
541+
else "disabled"
542+
),
534543
"enabled" if self.config.alerting.enabled else "disabled",
535544
"enabled" if self.config.billing.enabled else "disabled",
536545
"enabled" if self.config.ping.enabled else "disabled",

LibreNMS/wrapper.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
#! /usr/bin/env python3
22
"""
3-
wrapper A small tool which wraps services, discovery and poller php scripts
4-
in order to run them as threads with Queue and workers
3+
wrapper A small tool which wraps services, discovery and poller php scripts
4+
in order to run them as threads with Queue and workers
55
6-
Authors: Orsiris de Jong <contact@netpower.fr>
7-
Neil Lathwood <neil@librenms.org>
8-
Job Snijders <job.snijders@atrato.com>
6+
Authors: Orsiris de Jong <contact@netpower.fr>
7+
Neil Lathwood <neil@librenms.org>
8+
Job Snijders <job.snijders@atrato.com>
99
10-
Distributed poller code (c) 2015, GPLv3, Daniel Preussker <f0o@devilcode.org>
11-
All code parts that belong to Daniel are enclosed in EOC comments
10+
Distributed poller code (c) 2015, GPLv3, Daniel Preussker <f0o@devilcode.org>
11+
All code parts that belong to Daniel are enclosed in EOC comments
1212
13-
Date: Sep 2021
13+
Date: Sep 2021
1414
15-
Usage: This program accepts three command line arguments
16-
- the number of threads (defaults to 1 for discovery / service, and 16 for poller)
17-
- the wrapper type (service, discovery or poller)
18-
- optional debug boolean
15+
Usage: This program accepts three command line arguments
16+
- the number of threads (defaults to 1 for discovery / service, and 16 for poller)
17+
- the wrapper type (service, discovery or poller)
18+
- optional debug boolean
1919
2020
21-
Ubuntu Linux: apt-get install python-mysqldb
22-
FreeBSD: cd /usr/ports/*/py-MySQLdb && make install clean
23-
RHEL 7: yum install MySQL-python
24-
RHEL 8: dnf install mariadb-connector-c-devel gcc && python -m pip install mysqlclient
21+
Ubuntu Linux: apt-get install python-mysqldb
22+
FreeBSD: cd /usr/ports/*/py-MySQLdb && make install clean
23+
RHEL 7: yum install MySQL-python
24+
RHEL 8: dnf install mariadb-connector-c-devel gcc && python -m pip install mysqlclient
2525
26-
Tested on: Python 3.6.8 / PHP 7.2.11 / CentOS 8 / AlmaLinux 8.4
26+
Tested on: Python 3.6.8 / PHP 7.2.11 / CentOS 8 / AlmaLinux 8.4
2727
28-
License: This program is free software: you can redistribute it and/or modify it
29-
under the terms of the GNU General Public License as published by the
30-
Free Software Foundation, either version 3 of the License, or (at your
31-
option) any later version.
28+
License: This program is free software: you can redistribute it and/or modify it
29+
under the terms of the GNU General Public License as published by the
30+
Free Software Foundation, either version 3 of the License, or (at your
31+
option) any later version.
3232
33-
This program is distributed in the hope that it will be useful, but
34-
WITHOUT ANY WARRANTY; without even the implied warranty of
35-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
36-
Public License for more details.
33+
This program is distributed in the hope that it will be useful, but
34+
WITHOUT ANY WARRANTY; without even the implied warranty of
35+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
36+
Public License for more details.
3737
38-
You should have received a copy of the GNU General Public License along
39-
with this program. If not, see https://www.gnu.org/licenses/.
38+
You should have received a copy of the GNU General Public License along
39+
with this program. If not, see https://www.gnu.org/licenses/.
4040
41-
LICENSE.txt contains a copy of the full GPLv3 licensing conditions.
41+
LICENSE.txt contains a copy of the full GPLv3 licensing conditions.
4242
"""
4343

4444
import logging

0 commit comments

Comments
 (0)