def logall(): config = Config.readconfig() while config != 0: url = config["URLS"] if os.path.exists("logs"): pass else: os.mkdir("logs") thread_list = [] for m in url: # Instantiates the thread # (i) does not make a sequence, so (i,) t = threading.Thread(target=logs.log, args=(m,)) # Sticks the thread in a list so that it remains accessible thread_list.append(t) # Starts threads for thread in thread_list: thread.start() # This blocks the calling thread until the thread whose join() method is called is terminated. # From http://docs.python.org/2/library/threading.html#thread-objects for thread in thread_list: thread.join()
def logall(): config = Config.readconfig() while config != 0: url = config["URLS"] if os.path.exists("logs"): pass else: os.mkdir("logs") thread_list = [] for m in url: # Instantiates the thread # (i) does not make a sequence, so (i,) t = threading.Thread(target=logs.log, args=(m, )) # Sticks the thread in a list so that it remains accessible thread_list.append(t) # Starts threads for thread in thread_list: thread.start() # This blocks the calling thread until the thread whose join() method is called is terminated. # From http://docs.python.org/2/library/threading.html#thread-objects for thread in thread_list: thread.join()
def dash(self, **params): config = Config.readconfig() # Attempts to read the config. if config == 0: # Else it uses the Arguements to create a config. # organises make config data data = {str(key):str(value) for key,value in params.items()} url = [] for i, v in data.items(): url.append(v) # makes config Config.mkconfig(url) else: # If True it saves the data to a variable URLS = config["URLS"] refresh = config["refresh"] # Runs the script in the Parsing Model. Parses the XML Files from URL parse = Parsing.system() refresh = config["refresh"] # Returns the template with Parsed XML Data and The Refresh Integer from the Config. return self.render_template('home/dash.html', template_vars={'data': parse, 'refresh': refresh})
def dash(self, **params): config = Config.readconfig() # Attempts to read the config. if config == 0: # Else it uses the Arguements to create a config. # organises make config data data = {str(key): str(value) for key, value in params.items()} url = [] for i, v in data.items(): url.append(v) # makes config Config.mkconfig(url) else: # If True it saves the data to a variable URLS = config["URLS"] refresh = config["refresh"] # Runs the script in the Parsing Model. Parses the XML Files from URL parse = Parsing.system() refresh = config["refresh"] # Returns the template with Parsed XML Data and The Refresh Integer from the Config. return self.render_template('home/dash.html', template_vars={ 'data': parse, 'refresh': refresh })
def index(self): config = Config.readconfig() # Check if there is a config. if config != 0: # Else redirect the User to the Dashboard raise cherrypy.HTTPRedirect("Home/dash") else: # If True Return the template return self.render_template('home/index.html')
def settings(self): # get config data config = Config.readconfig() URLS = config["URLS"] refresh = config["refresh"] times = config["time"] # Return the template return self.render_template('home/settings.html', template_vars={'refresh': refresh, 'urls': URLS, 'time': times})
def index(self): config = Config.readconfig() # Check if there is a config. if config != 0: # Else redirect the User to the Dashboard raise cherrypy.HTTPRedirect("Home/dash") else: # If True Return the template return self.render_template('home/index.html')
def settings(self): # get config data config = Config.readconfig() URLS = config["URLS"] refresh = config["refresh"] times = config["time"] # Return the template return self.render_template('home/settings.html', template_vars={ 'refresh': refresh, 'urls': URLS, 'time': times })
def log(m): refresh = 20 config = Config.readconfig() refresh = config["refresh"] name = "" ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE monit = ET.parse(urllib.urlopen(m, context=ctx)) or ET.parse(m) root = monit.getroot() for i in root.findall("server/localhostname"): name = i.text logs.setup_logger(name, SiteConfig.home + "/logs/" + name + '.txt') logger = logging.getLogger(name) while True: data = ET.tostring(root) logger.info(data) time.sleep(float(refresh))
def log(m): refresh = 20 config = Config.readconfig() refresh = config["refresh"] name = "" ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE monit = ET.parse(urllib.urlopen(m, context=ctx)) or ET.parse(m) root = monit.getroot() for i in root.findall("server/localhostname"): name = i.text logs.setup_logger(name, SiteConfig.home + "/logs/" + name + '.txt') logger = logging.getLogger(name) while True: data = ET.tostring(root) logger.info(data) time.sleep(float(refresh))
def system(): # read config config = Config.readconfig() url = config["URLS"] parsed = [] # for loop of URls in config for m in url: data = {} de = [] hostlst = [] fs = [] # parse the xml whether its a local xml file or remote ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE monit = ET.parse(urllib.urlopen(m, context=ctx)) or ET.parse(m) root = monit.getroot() # find and save daemon xml data for i in root.findall("*[@type='3']"): daemon = {h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '} daemon.update({"mem": {h.tag: h.text for l in i.iter("memory") for h in l}}) daemon.update({"cpu":{h.tag: h.text for l in i.iter("cpu") for h in l}}) daemon.update({"port":{h.tag: h.text for l in i.iter("port") for h in l}}) loop(daemon) de.append(daemon) data.update({"process": de}) # find and save host xml data for i in root.findall("*[@type='4']"): host = {h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '} host.update({"port": {h.tag: h.text for l in i.iter("port") for h in l}}) loop(host) hostlst.append(host) data.update({"host": hostlst}) # find and save filesystem xml data for i in root.findall("*[@type='0']"): file = {h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '} file.update({"block": {h.tag: h.text for l in i.iter("block") for h in l}}) file.update({"inode": {h.tag: h.text for l in i.iter("inode") for h in l}}) loop(file) fs.append(file) data.update({"fs": fs}) # find and save system details xml data sys = {h.tag: h.text for i in root.findall("*[@type='5']") for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '} loop(sys) sys.update({"load": {h.tag: h.text for i in root.findall("*[@type='5']/system/load") for h in i}, "cpu": {h.tag: h.text for i in root.findall("*[@type='5']/system/cpu") for h in i}, "memory":{h.tag: h.text for i in root.findall("*[@type='5']/system/memory") for h in i}, "swap":{h.tag: h.text for i in root.findall("*[@type='5']/system/swap") for h in i}, "server": {h.tag: h.text for i in root.findall("server") for h in i}, 'platform': {h.tag: h.text for i in root.findall('platform') for h in i}}) loop(sys["server"]) data.update({"sys": sys}) netloc = urlparse.urlparse(m).netloc scheme = urlparse.urlparse(m).scheme data.update({"url": scheme + ":\\\\www." + netloc }) loop(data) parsed.append(data) return parsed
def duration(seconds): config = Config.readconfig() time = config["time"] if time == "Week Day Hour Minute Second": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) weeks, days = divmod(days, 7) if weeks == 0: date = '{}D {}H {}M {}S'.format(days, hours, minutes, seconds) elif days == 0: date = '{}H {}M {}S'.format(hours, minutes, seconds) elif hours == 0: date = '{}M {}S'.format(minutes, seconds) else: date = '{}W {}D {}H {}M {}S'.format(weeks, days, hours, minutes, seconds) elif time == "Day Hour Minute Second": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) if days == 0: date = '{}H {}M {}S'.format(hours, minutes, seconds) if hours == 0: date = '{}M {}S'.format(minutes, seconds) else: date = '{}D {}H {}M {}S'.format(days, hours, minutes, seconds) elif time == "Week Day Hour Minute": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) weeks, days = divmod(days, 7) if weeks == 0: date = '{}D {}H {}M'.format(days, hours, minutes) elif days == 0: date = '{}H {}M'.format(hours, minutes) elif hours == 0: date = '{}M'.format(minutes) else: date = '{}W {}D {}H {}M'.format(weeks, days, hours, minutes) elif time == "Year Day Hour Minute": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) weeks, days = divmod(days, 7) years, weeks = divmod(days, 52) if years == 0: date = '{}D {}H {}M'.format(days, hours, minutes) elif days == 0: date = '{}H {}M'.format(hours, minutes) elif hours == 0: date = '{}M'.format(minutes) else: date = '{}Y {}D {}H {}M'.format(years, days, hours, minutes) return str(date)
def system(): # read config config = Config.readconfig() url = config["URLS"] parsed = [] # for loop of URls in config for m in url: data = {} de = [] hostlst = [] fs = [] # parse the xml whether its a local xml file or remote ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE monit = ET.parse(urllib.urlopen(m, context=ctx)) or ET.parse(m) root = monit.getroot() # find and save daemon xml data for i in root.findall("*[@type='3']"): daemon = { h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n ' } daemon.update( {"mem": {h.tag: h.text for l in i.iter("memory") for h in l}}) daemon.update( {"cpu": {h.tag: h.text for l in i.iter("cpu") for h in l}}) daemon.update( {"port": {h.tag: h.text for l in i.iter("port") for h in l}}) loop(daemon) de.append(daemon) data.update({"process": de}) # find and save host xml data for i in root.findall("*[@type='4']"): host = { h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n ' } host.update( {"port": {h.tag: h.text for l in i.iter("port") for h in l}}) loop(host) hostlst.append(host) data.update({"host": hostlst}) # find and save filesystem xml data for i in root.findall("*[@type='0']"): file = { h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n ' } file.update( {"block": {h.tag: h.text for l in i.iter("block") for h in l}}) file.update( {"inode": {h.tag: h.text for l in i.iter("inode") for h in l}}) loop(file) fs.append(file) data.update({"fs": fs}) # find and save system details xml data sys = { h.tag: h.text for i in root.findall("*[@type='5']") for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n ' } loop(sys) sys.update({ "load": { h.tag: h.text for i in root.findall("*[@type='5']/system/load") for h in i }, "cpu": { h.tag: h.text for i in root.findall("*[@type='5']/system/cpu") for h in i }, "memory": { h.tag: h.text for i in root.findall("*[@type='5']/system/memory") for h in i }, "swap": { h.tag: h.text for i in root.findall("*[@type='5']/system/swap") for h in i }, "server": {h.tag: h.text for i in root.findall("server") for h in i}, 'platform': {h.tag: h.text for i in root.findall('platform') for h in i} }) loop(sys["server"]) data.update({"sys": sys}) netloc = urlparse.urlparse(m).netloc scheme = urlparse.urlparse(m).scheme data.update({"url": scheme + ":\\\\www." + netloc}) loop(data) parsed.append(data) return parsed
def duration(seconds): config = Config.readconfig() time = config["time"] if time == "Week Day Hour Minute Second": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) weeks, days = divmod(days, 7) if weeks == 0: date = '{}D {}H {}M {}S'.format(days, hours, minutes, seconds) elif days == 0: date = '{}H {}M {}S'.format(hours, minutes, seconds) elif hours == 0: date = '{}M {}S'.format(minutes, seconds) else: date = '{}W {}D {}H {}M {}S'.format(weeks, days, hours, minutes, seconds) elif time == "Day Hour Minute Second": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) if days == 0: date = '{}H {}M {}S'.format(hours, minutes, seconds) if hours == 0: date = '{}M {}S'.format(minutes, seconds) else: date = '{}D {}H {}M {}S'.format(days, hours, minutes, seconds) elif time == "Week Day Hour Minute": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) weeks, days = divmod(days, 7) if weeks == 0: date = '{}D {}H {}M'.format(days, hours, minutes) elif days == 0: date = '{}H {}M'.format(hours, minutes) elif hours == 0: date = '{}M'.format(minutes) else: date = '{}W {}D {}H {}M'.format(weeks, days, hours, minutes) elif time == "Year Day Hour Minute": minutes, seconds = divmod(int(seconds), 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) weeks, days = divmod(days, 7) years, weeks = divmod(days, 52) if years == 0: date = '{}D {}H {}M'.format(days, hours, minutes) elif days == 0: date = '{}H {}M'.format(hours, minutes) elif hours == 0: date = '{}M'.format(minutes) else: date = '{}Y {}D {}H {}M'.format(years, days, hours, minutes) return str(date)