Code Monkey home page Code Monkey logo

highvolt-dev / tmo-monitor Goto Github PK

View Code? Open in Web Editor NEW
86.0 14.0 16.0 87 KB

A lightweight, cross-platform Python 3 script that can monitor the T-Mobile Home Internet Nokia, Arcadyan, and Sagecom 5G Gateways for 4G/5G bands, cellular site (tower), and internet connectivity and reboots as needed or on-demand.

License: MIT License

Python 92.09% Shell 7.91%
tmobile t-mobile isp monitoring monitor monitoring-tool windows linux osx macosx

tmo-monitor's People

Contributors

andrewpardoe avatar benkesselring avatar delikat avatar highvolt-dev avatar hugoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tmo-monitor's Issues

Logging to email, telegram...somewhere

Have you considered allowing for an email or some other options that just basically says the gateway was rebooted? Email would have the timestamp. Might indicate if the issue is overheating. telegram-cli would have been perfect except it gives an error on pi and needs to have 2 lines commented out in the source then recompiled.

Version 2 Beta Feedback

Substantial work from @AndrewPardoe has lead to a new upcoming major version release, 2.0. This issue is intended to track any feedback regarding this release.

Specifically:

  • .env file and configuration override nuances
  • logging behavior
  • ping behavior (the ping implementation was slightly changed when extracting latency information for logging) - need to confirm that no regressions are introduced, particularly with Windows in the case of a "Network not reachable" edge case.

Could not post reboot request

Using Nokia 5G "trashcan" on firmware 1.2104.00.0286

2022/06/15 00:20:38 [DEBUG] Starting new HTTP connection (1): 192.168.12.1:80
2022/06/15 00:20:39 [DEBUG] http://192.168.12.1:80 "GET /dashboard_device_info_status_web_app.cgi HTTP/1.1" 200 649
2022/06/15 00:20:39 [INFO] Reboot requested.
2022/06/15 00:20:39 [INFO] Rebooting.
2022/06/15 00:20:39 [DEBUG] Starting new HTTP connection (1): 192.168.12.1:80
2022/06/15 00:20:39 [DEBUG] http://192.168.12.1:80 "GET /login_web_app.cgi?nonce HTTP/1.1" 200 369
2022/06/15 00:20:39 [DEBUG] Starting new HTTP connection (1): 192.168.12.1:80
2022/06/15 00:20:39 [DEBUG] http://192.168.12.1:80 "POST /login_web_app.cgi HTTP/1.1" 200 32
2022/06/15 00:20:39 [CRITICAL] Could not post reboot request, exiting.
(program terminates here)

Doesn't seem to be able to reboot the router, so it just exits?

Also all of this happens within a few seconds, it's not like it sends an initial reboot command then waits for the router, then fails.

Multiple consecutive pings in x time before you reboot due to drop outs or latency (due to bad weather etc)

At given times of the day and especially in bad weather you can experience "drop outs" that can last for 20-30 seconds. Right now this will trigger a reboot that adds another 2 minutes into the process. If the monitor was to do 4 pings 10 seconds apart before triggering a reboot this would allow for those moments of drop out or latency.

This seemed to be different enough from the "enhance ping" issue where it talks about multiple hosts vs multiple pings across a timeframe interval.

Add Linting Rules

Add linting rules for better consistency of code. Incorporate in GitHub Actions.

Add Predefined Band Groups

Add pre-defined band groups, e.g. low-band, mid-band, Sprint, T-Mobile, anchor bands (i.e. B2/B66), etc.

Enhanced Bootloop Prevention

Follow-up to #10

Bootloop prevention is currently implemented with an uptime check.

Add statefulness to prevent boot loops so that a given number of consecutive failures or a failure of a certain duration causes different behavior than endlessly rebooting.

Arcaydyan enBID coming up wrong

When I remove the first six characters (T-Mobile ID), then divide the remaining 8 digit number by 256, the tower ID matched what cellmapper.net showed for my connected tower. Discard the numbers after the decimal point, to get the correct enBID. I would be amenable to letting you ssh into my Linux Box, running Fedora 35, if you care to test it with a live unit. I do appreciate this effort you are putting out, for all of us who are using the Arc box. Using CGI on LTE tab, as the source, peel off the first 6 characters, then divide the remaining 8 digit number by 256, drop the characters after the decimal point, should give cell tower enBID that match the stuff reported to cellmapper.net. Hope this helps. Great work on this tool.

Python 3.x compatibility

capture_output kwarg for subprocess.run was introduced in Python 3.7 - instead use stdout=subprocess.PIPE, stderr=subprocess.PIPE

Reported by reddit user /u/Tractor_Boy_500

Provide an option to explicitly force IPv4 ping

I had issues when my Linux system didn't apparently handle IPv6 pings to Google very well, and for some reason tmo_monitor/gateway/base.py wanted to use IPv6 ping. It would be really nice to either explicitly force ping -4 by default, or allow the user to specify ping -4 as a command line option.

In my configuration I wanted to make double sure it didn't use IPv6 ping, so I just hardcoded base.py to add the -4 flag...

Possible 5G band restart regression in v2 beta

edit2: oops ๐Ÿคฆ I completely missed that the .env file now contains flags to reboot based on 4G/5G bands, default false. Might be worth adding these flags as CLI overrides since this is a change from the default behavior of v1? I can send a PR if the maintainers are open to it :)

original issue below
Just pulled the latest version and restarting based on 5G bands isn't working. My router is camping on n71 but running with -5 n41 doesn't cause a restart like it does on the v1 branch.

edit: I'm running MacOS 12.0.1

Logs:

> ./tmo-monitor.py admin [redacted] -5 n41 --print-config --log-all --logfile /dev/stdout
Password:
Script configuration:
  Login info:
    Username: admin
    Password: [redacted]
  Ping configuration:
    Host: google.com
    Count: 1
    Interval: 10
  Connection configuration:
    Secondary band: ['n41']
  Reboot settings:
    Reboot now: False
    Skip reboot: False
    Min uptime: 90
  Reboot on:
  General settings:
    Log file: /dev/stdout
    Log all: True
    Log delta: False

eNB ID check passed, on 27120.
Camping on B66.
Camping on n71.
No reboot necessary.
4G: B66 | 5G: n71 | eNB ID: 27120 | Avg Ping:  ms | Uptime: 223 sec
2022/01/08 02:36:36 [INFO] 4G: B66 | 5G: n71 | eNB ID: 27120 | Avg Ping:  ms | Uptime: 223 sec

Thanks for all your work on this! My trashcan is finally usable ๐Ÿ™

Support .env files & major refactoring of argument parsing

Hey there! First, thanks for the script!

I wanted to add (local) logging, but before I hacked on it I figured I'd add support for .env files and clean up the argument parsing a bit. I tried not to change the semantics but I haven't thoroughly tested yet.

What I've got is a pretty major refactor that's just one commit behind your repo's status.

https://github.com/AndrewPardoe/tmo-monitor/blob/config/tmo-monitor.py

If you like the refactor, I'm happy to integrate your multiple ping logic & submit a PR to merge everything back. If you don't like the refactor, I'll probably maintain a fork. I'm still testing so I haven't created a PR yet.

Please LMK.

No module named 'tailer'

I downloaded the 2.0.4 zip release and upgraded over my older working release.

pi@p314:~/tmo-monitor-main/bin $ ./tmo-monitor.py
Traceback (most recent call last):
File "./tmo-monitor.py", line 8, in
import tailer
ModuleNotFoundError: No module named 'tailer'

Boot Loop Prevention

Add statefulness to prevent boot loops so that a given number of consecutive failures or a failure of a certain duration causes different behavior than endlessly rebooting.

Script fails if not connected to 5G band

Executing:

tmo-monitor.py --ping-count 3 -4 B2 -5 n41 -5 n71 --model ARCKVD21

When the Ark device isn't connected to a 5g band, the JSON no longer contains a 5g section in the output, resulting in the following error:

2022/08/05 10:04:00 [DEBUG] Starting new HTTP connection (1): 192.168.12.1:80
2022/08/05 10:04:00 [DEBUG] http://192.168.12.1:80 "GET /TMI/v1/gateway?get=all HTTP/1.1" 200 906
Traceback (most recent call last):
File "/home/treddy/.local/bin/tmo-monitor.py", line 83, in
signal_info = gw_control.get_signal_info()
File "/home/treddy/.local/lib/python3.9/site-packages/tmo_monitor/gateway/arcadyan.py", line 69, in get_signal_info
nr_info = info['signal']['5g']['bands']
KeyError: '5g'

Output from gateway endpoint:

{
"device": {
"friendlyName": "5G Gateway",
"hardwareVersion": "R01",
"isEnabled": true,
"isMeshSupported": true,
"macId": "",
"manufacturer": "Arcadyan",
"manufacturerOUI": "001A2A",
"model": "KVD21",
"name": "5G Gateway",
"role": "gateway",
"serial": "",
"softwareVersion": "1.00.16",
"type": "HSID",
"updateState": "latest"
},
"signal": {
"4g": {
"bands": [
"b12"
],
"bars": 5.0,
"cid": 22,
"eNBID": ,
"rsrp": -73,
"rsrq": -6,
"rssi": -67,
"sinr": 17
},
"generic": {
"apn": "FBB.HOME",
"hasIPv6": true,
"registration": "registered",
"roaming": false
}
},
"time": {
"daylightSavings": {
"isUsed": false
},
"localTime": 1659687085,
"localTimeZone": "<-06>6",
"upTime": 306
}
}

Crashes Immediately on macOS

macOS 12.4
Python 3.9.13
tmo-monitor 2.0.0 beta6

All dependencies installed, as far as I know. The main script crashes with:

$ ./bin/tmo-monitor.py Password: 2022/06/20 18:42:29 [DEBUG] Starting new HTTP connection (1): 192.168.12.1:80 2022/06/20 18:42:29 [DEBUG] http://192.168.12.1:80 "GET /fastmile_radio_status_web_app.cgi HTTP/1.1" 200 3318 Traceback (most recent call last): File "/Users/Administrator/Downloads/tmo-monitor-2.0.0-beta6/./bin/tmo-monitor.py", line 83, in <module> signal_info = gw_control.get_signal_info() File "/usr/local/lib/python3.9/site-packages/tmo_monitor/gateway/nokia.py", line 141, in get_signal_info info = signal_request.json() File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 910, in json return complexjson.loads(self.text, **kwargs) File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads return _default_decoder.decode(s) File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

pip3 install .

Sorry, Python noob here.

On an uppdated RaspberryPi
Python 3.9.2
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
pip3 install .
yields
ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.

Help

Do I need to download the project and unpack it in the home directory?

Ping checks fail on macOS

When running latest main on macOS 12.0.1, ping checks fail with:

PING google.com (142.250.191.238): 56 data bytes
64 bytes from 142.250.191.238: icmp_seq=0 ttl=110 time=239.159 ms

--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 239.159/239.159/239.159/0.000 ms

Traceback (most recent call last):
  File "/Users/adelikat/src/tmo-monitor/./tmo-monitor.py", line 417, in <module>
    ping_ms = tc_control.ping(config.ping['ping_host'], config.ping['ping_count'],
  File "/Users/adelikat/src/tmo-monitor/./tmo-monitor.py", line 157, in ping
    result = ping_time(i)
  File "/Users/adelikat/src/tmo-monitor/./tmo-monitor.py", line 154, in ping_time
    return round(float(ping_ms.group(1)))
AttributeError: 'NoneType' object has no attribute 'group'

This happens because macOS prints stddev instead of mdev.

Arcadyan gateway doesn't always provide all signal information

When the Arcadyan gateway returns the status of the signal, it doesn't always provide both 4g and 5g bands if not connected. For example, my gateway pulls this currently:

{ "device": { "friendlyName": "5G Gateway", "hardwareVersion": "R01", "isEnabled": true, "isMeshSupported": true, "macId": MACADDRESS, "manufacturer": "Arcadyan", "manufacturerOUI": "001A2A", "model": "KVD21", "name": "5G Gateway", "role": "gateway", "serial": SERIAL, "softwareVersion": "1.00.16", "type": "HSID", "updateState": "latest" }, "signal": { "4g": { "bands": [ "b66" ], "bars": 2.0, "cid": 3, "eNBID": 778528, "rsrp": -116, "rsrq": -13, "rssi": -103, "sinr": 0 }

When this happens, there is a key error for ['signal']['5g']['bands'].

A more detailed installation procedure?

I have a pi with a fresh install of the latest version.

What do I need to do to install and then run this script?

I can run pip3 and, after a while, it returns a string of command line options.

I am a noob at python.

Have you looked at this...

https://github.com/geerlingguy/internet-pi

I have been running it for 3 months. It works with any ISP.

My TMHI was terrible during the day until about 3 weeks ago. Speeds are not great but very usable.

Thanks for sharing your work.

Dennis

internet=pi output...

Internet_connection_-_Grafana

32 0 Mbs

Ping check fails on Windows

The ping command on Windows has different output than on Linux which causes parsing issues:

Approximate round trip times in milli-seconds:
    Minimum = 39ms, Maximum = 46ms, Average = 42ms

not seeing .env in 2.0.0beta 4

Running on a raspberry pi, It is not seeing the .env file when I run python3 bin/tmo-monitor.py

I put the .env in the bin folder, then second guessed myself and put in in the tmo-monitor-2.0.0-beta4 folder. No luck either way.

Feature request: support for IPv6

IPv4 addresses are supported at ping hosts (e.g., 8.8.8.8), but IPv6 (e.g., 2001:4860:4860::8888) isn't on Linux as it requires the use of ping6 instead of ping.

It would be nice to support both.

Windows Compatibility

The script is not currently compatible with Windows due to its ping implementation. Conditionally translate ping flags to Windows equivalents. Check output for indications that Destination Host Unreachable.

For now, running with --skip-ping will work on Windows if that feature is not needed.

Credential Reuse

Provide method(s) for credentials to be re-used.

Because web api authentication uses hashing and app api authentication uses cleartext passwords, cannot simply just use hashed value.

Options include storing password in cleartext or encrypted at rest and providing the decryption key at runtime, e.g. with an environment variable. If storing in cleartext, should ensure read permissions are as strict as possible.

could not query site and could not post login

I am running the latest code. This morning, my internet dropped out. When I looked at logs I got the following:

2022/01/11 07:00:04 [INFO] 4G: B2 | 5G: n41 | eNB ID: 28646 | Avg Ping: 44 ms | Uptime: 158930 sec
2022/01/11 07:05:01 [CRITICAL] Could not post login request, exiting.
2022/01/11 07:05:01 [CRITICAL] Could not query site info, exiting.
2022/01/11 07:06:09 [ERROR] Could not ping google.com.
2022/01/11 07:06:09 [CRITICAL] Could not query modem uptime, exiting.
2022/01/11 07:06:17 [CRITICAL] Could not post login request, exiting.
2022/01/11 07:06:17 [CRITICAL] Could not query site info, exiting.
2022/01/11 07:06:43 [CRITICAL] Could not post login request, exiting.
2022/01/11 07:06:43 [CRITICAL] Could not query site info, exiting.

Any ideas why? I was able to log into my gateway from my laptop, so it was still on my local network. As soon as the reboot was complete, everything was fine and things were being logged like normal again.

2022/01/11 07:10:03 [INFO] 4G: B66 | 5G: n41 | eNB ID: 28646 | Avg Ping: 59 ms | Uptime: 94 sec
2022/01/11 07:12:46 [INFO] 4G: B66 | 5G: n41 | eNB ID: 28646 | Avg Ping: 84 ms | Uptime: 257 sec

Add --silent flag

Add --silent flag to suppress output to stdout. This will prevent cron from needing to redirect output.

Handle DNS Failures

Handle DNS failures in a more explicit way.

Pinging an IP address (e.g. 1.1.1.1 or 8.8.8.8) can indicate whether there is network connectivity regardless of DNS functionality.

Likewise, more explicitly checking that DNS resolution is working may be a desirable but separate health check.

More Robust Ping Health Check

Allow specifying multiple ping hosts, with the ability to reboot if either any or all of them fail (flags can specify the behavior).

Use technique other than ping to assess connection status

It looks like T-Mobile started blocking pings, and so the connection looks down even when it's not. This broke this tool for me โ€“ I'm assuming for others too.

We should add a different mechanism, such as DNS lookup or HTTP request.

Submit to PyPI

Submit to PyPI for expanded user reach and a more accessible route to using the script via pip install.

Unit Tests?

I see there are no unit tests.

Before I jump in head first writing tests, would you find it useful for this project?

How is the ping count supposed to be formatted?

I tried various choices and it looks to me like every time it's still only doing 1 ping.

pi@p314:~ $ /home/pi/tmo-monitor-main/tmo-monitor.py --ping-count 3 --skip-bands admin password
PING google.com (142.250.64.238) 56(84) bytes of data.
64 bytes from mia07s57-in-f14.1e100.net (142.250.64.238): icmp_seq=1 ttl=109 time=47.3 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 47.275/47.275/47.275/0.000 ms

No reboot necessary.
pi@p314:~ $ /home/pi/tmo-monitor-main/tmo-monitor.py --skip-bands --ping-count=1 admin password
PING google.com (142.250.64.238) 56(84) bytes of data.
64 bytes from mia07s57-in-f14.1e100.net (142.250.64.238): icmp_seq=1 ttl=109 time=54.8 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 54.781/54.781/54.781/0.000 ms

No reboot necessary.
pi@p314:~ $ /home/pi/tmo-monitor-main/tmo-monitor.py --skip-bands --ping-count=3 admin password
PING google.com (142.250.64.238) 56(84) bytes of data.
64 bytes from mia07s57-in-f14.1e100.net (142.250.64.238): icmp_seq=1 ttl=109 time=39.6 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 39.575/39.575/39.575/0.000 ms

Add logging of stats

Add logging of status checks so that the output can be used for analysis or with time series databases, graphing, and monitoring tools.

Add ability to specify output format (e.g. json)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.