message = "train departs in %(minutes)d" % rd.__dict__ + " minutes: " + bartdepart_dateObject.strftime('%I:%M%p') if debug: print message if bartdepart_dateObject >= (datetime.now() + timedelta(minutes=minutesOfLastNotice)): killcommand = "kill -9 "+str(os.getpid()); cmd2 = "terminal-notifier -message '" + str(message) + "' -execute '"+killcommand + "'" print cmd2 subprocess.Popen(cmd2, shell=True, stdout=subprocess.PIPE).stdout.read().rstrip() break else: print "Next depart is in %(minutes)d minutes at " % rd.__dict__ +d.strip()+'PM' break debugFile.writelines("\nbefore ispingable " + str(datetime.now())) try: debugFile.writelines(library.isPingable('google.com') + str(datetime.now())) # exit the script if I'm not at work if library.isPingable('google.com'): if not library.isPingable('confluence'): if not library.isPingable('jira'): print 'you''re not at work; exiting' exit() except: debugFile.writelines('error when pinging' + str(datetime.now())) debugFile.writelines("\nafter ispingable " + str(datetime.now())) time.sleep(60) debugFile.close()
{'name':'buildserver', 'uri':'buildserver','app': 'ping', 'failCounter':0}, {'name':'wdsgerrit', 'uri':'wdsgerrit','app': 'ping', 'failCounter':0}, {'name':'navapp-gerrit', 'uri':'navapp-gerrit','app': 'ping', 'failCounter':0}, ] # ensure we are only ever running one copy of this script library.singleton(__file__) while True: if is_macy_network(): for server in servers: if 'ping' in server['app']: print 'pinging '+server['name'] if not library.isPingable(server['uri']): server['failCounter'] = server['failCounter']+1 serverCount+=1 print str(serverCount) messages.append(server['name'] + " is down\n") if 'rest' in server['app']: rest_call(server['uri'],server['responseContains']) if 'sftp' in server['app']: sftp_login(server['uri'].split(';')[0],server['uri'].split(';')[1],server['uri'].split(';')[2]) if 'webserver' in server['app']: responseCode = get_status_code(server['uri']) if (responseCode <> 200): server['failCounter'] = server['failCounter']+1 serverCount+=1 messages.append(server['name'] + ' returning html response code: '+str(responseCode))
def is_macy_network(): if library.isPingable('jira') or library.isPingable('buildserver'): return True else: return False
cmd2 = "terminal-notifier -message '" + str( message) + "' -execute '" + killcommand + "'" print cmd2 subprocess.Popen( cmd2, shell=True, stdout=subprocess.PIPE).stdout.read().rstrip() break else: print "Next depart is in %(minutes)d minutes at " % rd.__dict__ + d.strip( ) + 'PM' break debugFile.writelines("\nbefore ispingable " + str(datetime.now())) try: debugFile.writelines( library.isPingable('google.com') + str(datetime.now())) # exit the script if I'm not at work if library.isPingable('google.com'): if not library.isPingable('confluence'): if not library.isPingable('jira'): print 'you' 're not at work; exiting' exit() except: debugFile.writelines('error when pinging' + str(datetime.now())) debugFile.writelines("\nafter ispingable " + str(datetime.now())) time.sleep(60) debugFile.close()