def checkSevThreshold(severity, sev_threshold): threshold = utils.getConfigValue(configObj, 'testssl', 'threshold') threshold_list = threshold.split(",") if sev_threshold.lower() == "critical": threshold_list.remove("high") threshold_list.remove("medium") threshold_list.remove("low") threshold_list.remove("ok") threshold_list.remove("info") elif sev_threshold.lower() == "high": threshold_list.remove("medium") threshold_list.remove("low") threshold_list.remove("ok") threshold_list.remove("info") elif sev_threshold.lower() == "medium": threshold_list.remove("low") threshold_list.remove("ok") threshold_list.remove("info") elif sev_threshold.lower() == "low": threshold_list.remove("ok") threshold_list.remove("info") elif sev_threshold.lower() == "ok": threshold_list.remove("info") if severity.lower() in threshold_list: return True else: return False
def check_restart_alert(rs): try: time = get_start_time() rscount = Restart.objects.filter(astro_id=rs['astro_id'], restart_time__gt=time).count() if rscount >= RESTART_ALERT_THRESHOLD: return str(rs["astro_id"]) + " restarted " + str( rscount) + " times in the past " + getConfigValue( DATA_DISPLAY_RANGE ) + " hours from the time of this alert.\n" return "" except Exception as e: logger.error("Exception in checking restart alert" + str(e)) raise e
def homePageView(request): """ Renders Home Page """ try: data = handle_UpdateHouse() hs = HouseSerializer(House.objects.filter(to_update=True), many=True) attributes = ["#", "House ID", "House Name", "Status", "Restarts", "Quick Interrupts", "Long Disconnect"] last_updated = getConfigValue(LAST_UPDATED) return render(request, template_name='HouseHealth/layouts.html', context={"house_data": hs.data, "attributes": attributes, "last_updated": last_updated}) except Exception as e: print(str(e)) raise Http404("Error")
def main(args): testSSLPath = None testSSLResultsFile = None sev_threshold = None uri = None if args.testsslpath: testSSLPath = args.testsslpath else: utils.getConfigValue(configObj, 'testssl', 'testSSLPath') if args.outputfile: testSSLResultsFile = args.outputfile else: utils.getConfigValue(configObj, 'testssl', 'testSSLResultsFile') if args.threshold: sev_threshold = args.threshold else: utils.getConfigValue(configObj, 'testssl', 'min_threshold') if args.uri: uri = args.uri else: utils.getConfigValue(configObj, 'default', 'uri') #threshold = utils.getConfigValue(configObj, 'testssl', 'threshold') threshold = utils.getConfigValue(configObj, 'testssl', 'threshold') threshold_list = threshold.split(",") if sev_threshold.lower() in threshold_list: if uri: testSSL(testSSLPath, uri, testSSLResultsFile, sev_threshold) else: print("[Error] Host or URI not defined...") exit else: print("[Error] Unknown threshold value. Please enter a valid one from the list:critical, high, medium, low, ok or info.")
def checkQuickInterrupt(self, range): try: interrupt_bin = {} counter = 0 while (1): payload = {'query': 'HOUSE_ID:' + self.house_id + ' AND ENV:PROD', 'range': range, 'fields': 'DYFO_TIME,Message_ASTRO_ID,Message_PIN_D', 'filter': 'streams:' + QUICK_INTERRUPT_STREAM_ID, 'offset': 150 * counter} data = make_graylog_request(payload, GRAYLOG_SEARCH_RELATIVE) if data == None or 'messages' not in data or len(data['messages']) == 0: break for element in data['messages']: dyfo_time = element['message']['DYFO_TIME'] astro_id = element['message']['Message_ASTRO_ID'] pin_id = element['message']['Message_PIN_D'] if astro_id not in self.astros: continue epoch = int(time.mktime(time.strptime(dyfo_time, DYFO_TIME_FORMAT_INPUT))) epoch = epoch - (epoch % int(getConfigValue(INTERRUPT_BIN_VALUE))) if astro_id not in interrupt_bin: interrupt_bin[astro_id] = {} if pin_id not in interrupt_bin[astro_id]: interrupt_bin[astro_id][pin_id] = {} if epoch not in interrupt_bin[astro_id][pin_id]: interrupt_bin[astro_id][pin_id][epoch] = 0 interrupt_bin[astro_id][pin_id][epoch] += 1 counter += 1 # print(interrupt_bin) final_interrupts = get_severe_quick_interrupts(interrupt_bin, self.astros, self.house_id) return final_interrupts except Exception as e: logger.error("Exception in checking quick interrupts. Exception" + str(e)) raise e
header.write('# [email protected]\n'.encode()) header.write('#\n\n'.encode()) # Directive tool directive = utils.directive(header, DRAM_BUF_ADDR, useHexValuesPrefix) header.write('# Header prefix'.encode()) header.write(headerScriptPrefix.encode()) header.write('\n\n'.encode()) header.write('# Partitions'.encode()) for sectionName in parts: part = config[sectionName] name = sectionName.replace('part/', '') create = utils.str2bool(utils.getConfigValue(part, 'create', '')) size = utils.getConfigValue(part, 'size', 'NOT_SET') erase = utils.str2bool(utils.getConfigValue(part, 'erase', '')) type = utils.getConfigValue(part, 'type', 'NOT_SET') imageFile = utils.getConfigValue(part, 'imageFile', 'NOT_SET') chunkSize = utils.sizeInt(utils.getConfigValue(part, 'chunkSize', '0')) lzo = utils.str2bool(utils.getConfigValue(part, 'lzo', '')) memoryOffset = utils.getConfigValue(part, 'memoryOffset', 'NOT_SET') print("\n") print("[i] Processing partition") print("[i] Name: {}".format(name)) print("[i] Create: {}".format(create)) print("[i] Size: {}".format(size)) print("[i] Erase: {}".format(erase)) print("[i] Type: {}".format(type))
def readGuidelines(): guidelinesFile = utils.getConfigValue(configObj, 'guidelines', 'guidelinesFile') with open(guidelinesFile, 'r') as json_file: json_data = json.load(json_file) return json_data
import argparse import utils # Defaults csvdelimiter = "@@" # data might contain commas, semicolon etc. So, it is safe to use a delimiter that doesn't exists in the string. eoldelimiter = "@@@" # end of line delimiter # testSSLPath = "/home/asadasivan/testssl.sh/testssl.sh" # outputFile = "/tmp/testSSL.json" # sev_threshold = "high" #guidelinesFile = 'guidelines.json' #threshold = ["critical","high","medium","low","ok","info"] configFile = 'app.cfg' configObj = utils.readConfig(configFile) reportName = utils.getConfigValue(configObj, 'report', 'reportName') #threshold = utils.getConfigValue(configObj, 'testssl', 'threshold') deviceType = "Device type:" + utils.getConfigValue(configObj, 'default', 'devicetype') version = "Version:" + utils.getConfigValue(configObj, 'default', 'version') uri = "URI:" + utils.getConfigValue(configObj, 'default', 'uri') reportTitle = utils.getConfigValue(configObj, 'report', 'reportTitle') def testSSL(testSSLPath, uri, testSSLoutputFile, sev_threshold): #output = subprocess.check_output("testssl.sh --jsonfile " + jsonFile + host) print("[Info] Please wait currently running SSL/TLS tests...") # # get current date and time # currentDateTime = datetime.datetime.now() # # append the file with current date and time # outputFile = outputFile + "_" + currentDateTime.strftime("%Y-%m-%d_%H-%M-%S") + ".json"
#!/usr/bin/env python3 import os import json import math import utils import datetime from consts import * # check cache file data = utils.loadJson(CACHE_USAGE) if not data: try: # get config gSheetId = utils.getConfigValue(None, XFINITY_GSHEET) gSheetUrl = utils.getGoogleSheetUrl(gSheetId) # update current usage book = utils.openGoogleSheet(gSheetId) dataSheet = book.get_worksheet(0) date = dataSheet.acell(DATE_CELL).value cap = int(dataSheet.acell(CAP_CELL).value.split()[0]) target = int(dataSheet.acell(TARGET_CELL).value.split()[0]) usage = int(dataSheet.acell(USAGE_CELL).value.split()[0]) today = int(dataSheet.acell(TODAY_CELL).value.split()[0]) # build data data = { 'date': date, 'cap': cap,
# logging: we need to remove handlers as xfinity-usage lib defined its own for handler in log.root.handlers[:]: log.root.removeHandler(handler) # add our now logLevel = log.DEBUG if args.debug else log.INFO if isCgi or args.log: log.basicConfig(filename='./xfinity-usage-tracker.log', filemode='w', level=logLevel) else: log.basicConfig(level=logLevel) # get config xfinityUser = utils.getConfigValue(args, XFINITY_USER) xfinityPass = utils.getConfigValue(args, XFINITY_PASS) xfinityOffset = int(utils.getConfigValue(args, XFINITY_OFFSET, 0)) xfinityBrowser = utils.getConfigValue(args, XFINITY_BROWSER, 'chrome-headless') dateFormat = utils.getConfigValue(args, DATE_FORMAT, DEFAULT_DATE_FORMAT) warnThreshold = utils.getConfigValue(args, XFINITY_WARNING, -1) gSheetId = utils.getConfigValue(args, XFINITY_GSHEET) gSheetUrl = utils.getGoogleSheetUrl(gSheetId) # default warnThreshold = 0.90 if warnThreshold < 0 else float(warnThreshold) # check if not xfinityUser or not xfinityPass: log.critical('Environment not properly setup. Aborting') if isCgi: