crypt = gpg.encrypt(body, dudes) if not crypt.ok: body = '### REDACTED DUE TO ENCRYPTION ERROR: {0} ###\n\nIntended recipients: {1}'.format( crypt.status, dudes) else: body = crypt.data except: pass # Assemble the mail message msg = MIMEText(body) if have_config == True: s = ServerConfig() facility_code = s.get_string('facility_code') else: facility_code = None host_name = socket.getfqdn() sender = 'root@' + host_name recipient = 'root' prefix = '' if (facility_code): prefix = facility_code + ": " msg['Subject'] = prefix + args.subject msg['From'] = sender msg['To'] = recipient if args.cc is not None:
#!/usr/bin/python2 # Include GWN packages import sys sys.path.append("/opt/gwn/python") from config import ServerConfig try: s = ServerConfig() print s.get_string('facility_code') except: print 'UNKNOWN'
except: info['server_type'] = 'unknown' # Gather Facility code # -------------------- try: if (os.path.exists('/etc/FacilityCode.txt')): # Old-school A3 servers info['facility_code'] = read_line_from_file('/etc/FacilityCode.txt') else: # New S4 servers sys.path.append('/opt/gwn/python') from config import ServerConfig config = ServerConfig() info['facility_code'] = config.get_string('facility_code') except: pass # Gather the server build version # ------------------------------- try: info['build_version'] = read_line_from_file('/etc/GWNBuild.txt') except: pass # Gather the server's uptime # -------------------------- try:
sleep_time = 5 # Enter infinite loop of fetching next job from job relay # ------------------------------------------------------- while True: try: log.info('=== Looking for the next job ===') # We need to build a JobRelay instance for the initial contact. We don't know # the current jobId or name yet, so that will be updated later. jr_params = { 'relay_host': args.relay_host, 'my_server_code': server_config.get_string('facility_code', False), 'my_host_name': server_config.get_string('full_host_name', False), 'my_mac': mac, 'log': log } jr = JobRelay(**jr_params) # Check if there are scripts to run resp_obj = jr.fetch_job() if resp_obj['next_job'] is None: log.info('No jobs waiting for me. Going back to sleep.') sleep_time = DEFAULT_SLEEP_TIME