Beispiel #1
0
def push_current_ip():
    '''
    Pushes the latest IP to slack

    If the latest detected IP is the same as the cached IP, then no message is sent
    '''
    do_setup()
    last_heartbeat = datetime.datetime.now()

    # Send a heartbeat on startup
    heartbeat(last_heartbeat, True)
    while(True):
        cached = get_cached_ip()
        new = get_external_ip()
        if not new:
            print("Unable to get external IP")
            time.sleep(FAILURE_SLEEP_DELAY)
            continue
        elif not cached or cached != new:
            print("Cached IP ({}) is different from cached IP ({}). Updating slack".format(cached, new))
            success = update_slack(new)
            if success:
                # Update the cache file with the new IP
                put_cached_ip(new)
                time.sleep(SUCCESS_SLEEP_DELAY)
            else:
                time.sleep(FAILURE_SLEEP_DELAY)
            continue
        else:
            print("Cached IP is same as current IP")
            if heartbeat(last_heartbeat):
                last_heartbeat = datetime.datetime.now()
            time.sleep(SUCCESS_SLEEP_DELAY)
def main(filename, server, key, ip, fuzzy):
    if not ip:
        ip = getip.get_external_ip()
    LOGGER.info('Using IP: {}'.format(ip))

    retcodes = list()
    if filename:
        LOGGER.info('File {} found'.format(filename))
        with open(filename, 'r') as domain_csv:
            reader = csv.reader(domain_csv, delimiter=',')
            for row in reader:
                retcode = update_ip(server=row[0], key=row[1], ipaddr=ip, fuzzy=fuzzy)
                retcodes.append(retcode)
    else:
        for server_id in server:
            retcode = update_ip(server=server_id, key=key, ipaddr=ip, fuzzy=fuzzy)
            retcodes.append(retcode)

    if any(retcodes):
        # There was an error
        return 1
    else:
        # Everything's a-ok
        return 0
def _grab_ip():
	ipaddr = getip.get_external_ip()
	return ipaddr
Beispiel #4
0
def _grab_ip():
	ipaddr = getip.get_external_ip()
	return ipaddr