Пример #1
0
def file_exists(path, filename):
    for file_or_folder in os.listdir(path):
        if file_or_folder == filename:
            return True
    return False


(RPC, RPCUSER, RPCPASS,
 WHITELIST) = load_credentials("/var/homebridge/rpc3control/.credentials")

RPCUSER = None
#RPCUSER= str(sys.argv[2])

#telnet into unit and turn off outlet
r = rpc3Control(RPC, RPCUSER)
r.outlet(OUTLET, 'off')

lock_filename = 'telnetrunning.txt'
fileexists = file_exists("/var/homebridge/rpc3control/", lock_filename)

#if status file exists, read it and update timestamp and outlet status for the turned off outlet. Also mark the file with updated status flag.
if (fileexists):
    my_file = open(lock_filename, 'r')
    statearray = [line.split(',') for line in my_file]
    sttime = str(int(round(time.time() * 1000)))
    statearray[0][0] = sttime
    statearray[0][1] = "updated"
    statearray[OUTLET][1] = "False"
    my_file.close()
    with open(lock_filename, 'w') as my_file:
Пример #2
0
TIMEOUT = 3
CNT = 3

(RPC, RPCUSER, RPCPASS,
 WHITELIST) = load_credentials("/retina/check_dsl/.credentials")

# syslog.syslog(syslog.LOG_NOTICE, 'Checking network.')

if __name__ == '__main__':
    count = 1
    while (count < (CNT + 1)):
        syslog.syslog(syslog.LOG_NOTICE, "Checking DSL... Try #%d" % count)
        result = do_one(UPLINK, TIMEOUT)

        if result != None:
            # we're good.
            syslog.syslog(syslog.LOG_NOTICE, "PING OK. Try #%d" % count)
            sys.exit(0)

        syslog.syslog(syslog.LOG_NOTICE, "PING FAILED. Try #%d" % count)
        count += 1

    # f**k, the network is down!
    syslog.syslog(syslog.LOG_NOTICE, 'PING FAILED. Rebooting DSL Modem')

    r = rpc3Control(RPC, RPCUSER, RPCPASS, False)
    r.outlet(OUTLET, 'reboot')

    syslog.syslog(syslog.LOG_NOTICE, 'Reboot complete.')
    sys.exit(1)
Пример #3
0
OUTLET=6
TIMEOUT=3
CNT=3

(RPC, RPCUSER, RPCPASS, WHITELIST) = load_credentials("/retina/check_dsl/.credentials")

# syslog.syslog(syslog.LOG_NOTICE, 'Checking network.')

if __name__ == '__main__': 
    count = 1
    while (count < (CNT+1)): 
        syslog.syslog(syslog.LOG_NOTICE, "Checking DSL... Try #%d" % count)
        result = do_one(UPLINK, TIMEOUT)

        if result != None:
            # we're good. 
            syslog.syslog(syslog.LOG_NOTICE, "PING OK. Try #%d" % count)
            sys.exit(0)

        syslog.syslog(syslog.LOG_NOTICE, "PING FAILED. Try #%d" % count)
        count += 1

    # f**k, the network is down!
    syslog.syslog(syslog.LOG_NOTICE, 'PING FAILED. Rebooting DSL Modem')
        
    r = rpc3Control(RPC, RPCUSER, RPCPASS, False)
    r.outlet(OUTLET, 'reboot')

    syslog.syslog(syslog.LOG_NOTICE, 'Reboot complete.')
    sys.exit(1)
Пример #4
0
RPC = None
RPCUSER = None
RPCPASS = None
TIMEOUT = 5


def usage():
    print "\nUsage: %s outlet_number (on|off|reboot|status)\n" % sys.argv[0]
    sys.exit(1)


(RPC, RPCUSER, RPCPASS) = load_credentials()

# sanity check
if len(sys.argv) != 3:
    usage()

outlet = int(sys.argv[1])
state = sys.argv[2]

if (outlet < 1 or outlet > 8) or (state
                                  not in ['on', 'off', 'reboot', 'status']):
    usage()

r = rpc3Control(RPC, RPCUSER, RPCPASS, True)
if state == 'status':
    (status, name) = r.outlet_status(outlet)
    print "Outlet %d \"%s\" is %s" % (outlet, name, ["off", "on"][int(status)])
else:
    r.outlet(outlet, state)
Пример #5
0
from rpc3Control import *
from ping import * 

RPC=None
RPCUSER=None
RPCPASS=None
TIMEOUT=5

def usage():
    print "\nUsage: %s outlet_number (on|off|reboot|status)\n" % sys.argv[0]
    sys.exit(1)

(RPC, RPCUSER, RPCPASS) = load_credentials()

# sanity check
if len(sys.argv) != 3:
    usage()

outlet = int(sys.argv[1])
state  = sys.argv[2]

if (outlet < 1 or outlet > 8) or (state not in ['on','off','reboot','status']):
    usage()

r = rpc3Control(RPC, RPCUSER, RPCPASS, True)
if state == 'status':
    (status,name) = r.outlet_status(outlet)
    print "Outlet %d \"%s\" is %s" % (outlet, name, ["off","on"][int(status)])
else:
    r.outlet(outlet, state)