aboutsummaryrefslogtreecommitdiff
path: root/thumper.py
blob: b9d09db4beba223e5a8b471b67c2a7defdfc5cc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
#------------------------------------------------------------------- thumper.py
# Check the backyard temperature sensors  
#
# (C) D Delmar Davis 2023 
#
# Note: POC lots of hard coded foo here....
# it takes about a minute and 20 seconds to come back so..
# bunnyfoofoo's crontab should look like this
# */2 * * * * /usr/local/bin/thumper.py

import socket
import subprocess

#---------------------------------------------------------------- isExporting()
# Check to see if node exporter is running on thumper.
#
def isExporting():
    try:
        # connect to the host -- tells us if the host is actually
        # reachable
        sock = socket.create_connection(("thumper", 9100),timeout=3)
        if sock is not None:
            print('Found da wabbit')
            sock.close
        return True
    except OSError:
        pass
    return False

#---------------------------------------------------------------- kickThumper()
# Make sure the poe port is on and powercycle that port
#
# https://www.devwithimagination.com/2022/08/07/restarting-poe-via-ssh-on-a-usw-lite-16-poe/

def kickThumper():
    ret = subprocess.call(["ssh",
                            "root@henri-le-renne",
                            "swctrl poe set auto id 6"]);
    ret = subprocess.call(["ssh", 
                           "root@henri-le-renne",
                           "swctrl poe restart id 6"]);


#------------------------------------------------------------------- __main__()
# Check to see if thumper is exporting and if not reset.
#
if __name__ == '__main__':
    if (not isExporting()) :
        print("Thumpers not talking. Going to kick it")
        kickThumper()