aboutsummaryrefslogtreecommitdiff
path: root/pykeepalive.py
blob: e4d54afb822852d2c3e01ad2ce35539e759f401c (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
#/bin/python3

import sys, time
import tailhead

from config import *

import tools
import commands
import file
import log

if len(sys.argv) == 1:
    log.tail_log()
    if commands.multi_ping(HOSTS, INTERFACE) == 0:
        file.log_write("ONLINE")
    else:
        print("Ooops, we're offline!")
        file.log_write("OFFLINE >> RESETING INTERFACE [{}]".format(INTERFACE))
        print(">> Reseting interface [{}]...".format(INTERFACE))
        ip, gateway, subnet = commands.uqmi_current_settings()
        commands.ifconfig_update(INTERFACE, ip, subnet)
        commands.route_update(gateway)
elif len(sys.argv) == 2:
    if sys.argv[1] == "tail":
        log.tail_log()
        for line in tailhead.follow_path(LOG_PATH_FILE):
            if line is not None:
                print(tools.status_color(line))
            else:
                time.sleep(1)
    elif sys.argv[1] == "cat":
        log.tail_log()
        with open(LOG_PATH_FILE) as f:
           for line in f:
               print(tools.status_color(line), end="")
    else:
        tools.show_help()
else:
    tools.show_help()