Skip to content

Commit

Permalink
Merge pull request #16 from andrewfraley/exit_on_error
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
andrewfraley authored May 9, 2021
2 parents a8c80e6 + 86550ae commit fbab723
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM python:3.8.5-alpine

ENV arris_stats_debug False
ENV destination influxdb
ENV sleep_interval 300
ENV modem_url https://192.168.100.1/cmconnectionstatus.html
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ Config settings can be provided by the config.ini file, or set as ENV variables.


### Debugging
```pipenv run python3 sb8200_stats.py --debug --config config.ini```

You can enable debug logs in three ways:

1. Use --debug when running from cli
- ```pipenv run python3 sb8200_stats.py --debug --config config.ini```
2. Set ENV variable ```arris_stats_debug = true```
3. Set config.ini ```arris_stats_debug = true```

## InfluxDB
The database will be created automatically if the user has permissions (config.ini defaults to anonymous access). You can set the database name in config.ini using the [INFLUXDB] database parameter.
Expand Down
15 changes: 14 additions & 1 deletion src/arris_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def main():
config_path = args.config
config = get_config(config_path)

# Re-init the logger if we set arris_stats_debug in ENV or config.ini
if config['arris_stats_debug']:
init_logger(True)

sleep_interval = int(config['sleep_interval'])
destination = config['destination']
modem_model = config['modem_model']
Expand Down Expand Up @@ -111,6 +115,7 @@ def get_config(config_path=None):
default_config = {

# Main
'arris_stats_debug': False,
'destination': 'influxdb',
'sleep_interval': 300,
'modem_url': 'https://192.168.100.1/cmconnectionstatus.html',
Expand Down Expand Up @@ -439,7 +444,15 @@ def init_logger(debug=False):
else:
level = logging.INFO

logging.basicConfig(level=level, format=log_format)
# https://stackoverflow.com/a/61516733/866057
try:
root_logger = logging.getLogger()
root_logger.setLevel(level)
root_handler = root_logger.handlers[0]
root_handler.setFormatter(logging.Formatter(log_format))
except IndexError:
logging.basicConfig(level=level, format=log_format)



if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion src/config.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
arris_stats_debug = False
destination = influxdb
sleep_interval = 300
modem_url = https://192.168.100.1/cmconnectionstatus.html
Expand All @@ -9,7 +10,7 @@ modem_model = sb8200
exit_on_auth_error = True
exit_on_html_error = True
clear_auth_token_on_html_error = True
sleep_before_exit = False
sleep_before_exit = True
influx_host = localhost
influx_port = 8086
influx_database = cable_modem_stats
Expand Down
3 changes: 2 additions & 1 deletion tests/test_arris_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import unittest
import tempfile
import arris_stats
import src.arris_stats as arris_stats


class TestArrisStats(unittest.TestCase):
Expand All @@ -11,6 +11,7 @@ class TestArrisStats(unittest.TestCase):
default_config = {

# Main
'arris_stats_debug': False,
'destination': 'influxdb',
'sleep_interval': 300,
'modem_url': 'https://192.168.100.1/cmconnectionstatus.html',
Expand Down

0 comments on commit fbab723

Please sign in to comment.