def load_systems(self, vapps, checks): """ Load systems from the database. Arguments: checks (List(Check,int)): List of pairs of systems and the check to associate a system with Returns: List(System): A list of systems """ systems = [] system_rows = db.getall('system') for system_name, vapp_name, host in system_rows: schecks = [] for check, sid in checks: if sid == system_name: schecks.append(check) vapp = vapps[vapp_name] system = System(system_name, vapp, host, schecks) vapp.systems.append(system) # Update link from checks to this system for check in schecks: check.system = system systems.append(system) return systems
def main(): """ The main function, mostly because I'm a shit python dev and my files can get REALLY CLUTTERED. What this script does is parse through /g/, finds any wdg generals, and if it detects any post that has the format of keyword1: data1, keyword2: data2, etc, it will be parsed and added here the function below is mostly for showcasing it. """ wdgPosts = findwdg() p = MyHTMLParser() db.init() testme=True for i in wdgPosts.json()["posts"]: p.feed(i["com"]) parsedpost=parsepost(p.pop()) if(parsedpost!=None): if(i.get("tim") != None): parsedpost["image"] = "https://i.4cdn.org/g/"+str(i["tim"])+i["ext"] # parsedpost["image"] = pars if(testme): parsedpost["progress"]="; drop table projects; --" testme=False db.insertentry(parsedpost) p.close() import pprint p = pprint.PrettyPrinter() list(map(lambda i:p.pprint(i), db.getall()))
def load_checks(self, check_ios): """ Load checks from the database. Arguments: check_ios (Dict(int->List(CheckIO))): Mapping of check IDs to a list of CheckIOs to associate checks with Returns: List(Check,int): A list of checks and the ID of their associated systems """ checks = [] check_rows = db.getall('service_check') for check_id, name, system, port, check_string, poller_string in check_rows: # Build check ios = check_ios[check_id] check_function = load_module(check_string) poller_class = load_module(poller_string) poller = poller_class() check = Check(check_id, name, port, check_function, ios, poller) # Update link from check IOs to this check for check_io in ios: check_io.check = check checks.append((check, system)) return checks
def load_vapps(self): """ Load vApps from the database. Returns: Dict(str->Vapp): Mapping of vApp base names to vApps """ vapps = {} vapp_rows = db.getall('vapp') for base_name, subnet, netmask in vapp_rows: vapp = Vapp(base_name, subnet, netmask) vapps[base_name] = vapp return vapps
def load_domains(self): """ Load domains from the database. Returns: List(Domain): List of domains """ domains = [] domain_rows = db.getall('domain') for fqdn, in domain_rows: domain = Domain(fqdn) domains.append(domain) return domains
def load_teams(self): """ Load teams from the database. Returns: Dict(int->Team): A mapping of team IDs to Teams """ teams = {} rows = db.getall('team') for team_id, name in rows: team = Team(team_id, name) teams[team_id] = team return teams
def revert_log(): teams = {} for team in wm.teams: teams[team.id] = team.name if current_user.name == 'admin': reverts = db.getall('revert_log', orderby='time DESC') else: reverts = db.get('revert_log', ['*'], where='team_id=%s', orderby='time DESC', args=(current_user.team.id, )) return render_template('vcloud/revert_log.html', teams=teams, reverts=reverts)
def random_burp(ircsock, channel, last_burp): """ Every working hour there is a possibility we burp out a ticket to do to remind everyone... """ tickets = db.getall(ticket_type='active') if ((datetime.now().day != last_burp.day and datetime.now().hour != last_burp.hour and datetime.now().hour > 9 and datetime.now().hour < 18 and datetime.now().minute == 0 and (random.randint(0, 2) > 0) and len(tickets) > 0)): # Display one random ticket to do sendmsg(ircsock, channel, "Need something to do?") show_one(ircsock, channel, tickets[random.randint(0, len(tickets) - 1)]) last_burp = datetime.now() return last_burp
def application(env, start_response): """ The WSGI application """ body = '' try: length = int(env.get('CONTENT_LENGTH', '0')) except ValueError: length = 0 if length != 0: body = env['wsgi.input'].read(length) args = urlparse.parse_qs(body) # Add a new tickets and redirect to standard location (reload # won't trigger any new entries or such) if env['PATH_INFO'] == '/new': db.add(args.get("ticket")[0]) start_response('301 Redirect', [('Location', '/')]) return [] # List old tickets oldtickets = tickets_table(db.getall(ticket_type='active')) if env['PATH_INFO'] == '/edit': # Tiny edit (inlined) print("Args: " + str(args)) target, index = args.get('id')[0].split('_') value = args.get('value')[0] if target == "done": db.set(target, done_snowflake[value], index) else: db.set(target, value, index) response_body = cgi.escape(value) else: # Redraw main interface response_body = html % { "tickets": str(oldtickets), "finished": finished, "unfinished": unfinished } status = '200 OK' response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) return [response_body]
def application(env, start_response): """ The WSGI application """ body = '' try: length = int(env.get('CONTENT_LENGTH', '0')) except ValueError: length = 0 if length != 0: body = env['wsgi.input'].read(length) args = urlparse.parse_qs(body) # Add a new tickets and redirect to standard location (reload # won't trigger any new entries or such) if env['PATH_INFO'] == '/new': db.add(args.get("ticket")[0]) start_response('301 Redirect', [('Location', '/')]) return [] # List old tickets oldtickets = tickets_table(db.getall(ticket_type='active')) if env['PATH_INFO'] == '/edit': # Tiny edit (inlined) print("Args: " + str(args)) target, index = args.get('id')[0].split('_') value = args.get('value')[0] if target == "done": db.set(target, done_snowflake[value], index) else: db.set(target, value, index) response_body = cgi.escape(value) else: # Redraw main interface response_body = html % {"tickets": str(oldtickets), "finished": finished, "unfinished": unfinished} status = '200 OK' response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) return [response_body]
def random_burp(ircsock, channel, last_burp): """ Every working hour there is a possibility we burp out a ticket to do to remind everyone... """ tickets = db.getall(ticket_type='active') if ((datetime.now().day != last_burp.day and datetime.now().hour != last_burp.hour and datetime.now().hour > 9 and datetime.now().hour < 18 and datetime.now().minute == 0 and (random.randint(0, 2) > 0) and len(tickets) > 0)): # Display one random ticket to do sendmsg(ircsock, channel, "Need something to do?") show_one(ircsock, channel, tickets[random.randint(0, len(tickets)-1)]) last_burp = datetime.now() return last_burp
def get_reverts(self): revert_rows = db.getall('revert_log') reverts = {} for team in self.teams: if team.id not in reverts: reverts[team.id] = {} for system in self.systems: if system not in reverts[team.id]: reverts[team.id][system.name] = 0 penalty = self.settings['revert_penalty'] for timestamp, team_id, system in revert_rows: reverts[team_id][system] += 1 for team_id in reverts.keys(): total = 0 for system in reverts[team_id].keys(): total += reverts[team_id][system] * penalty reverts[team_id]['total'] = total return reverts
def load_check_ios(self, credentials): """ Load CheckIOs from the database. Poll inputs will be left in the following format: List(input_class_str, Dict(attr->value)) Arguments: credentials (List(Credential)): List of credentials to associate input-output pairs with Returns: Dict(int->List(CheckIO)): Mapping of check IDs to a list of CheckIOs """ check_ios = {} # Gather all of the check IOs check_io_rows = db.getall('check_io') for check_io_id, poll_input, expected, check_id in check_io_rows: # Gather all of the credentials which belong to this check IO cred_input_rows = db.get('cred_input', ['*'], where='check_io_id=%s', args=(check_io_id)) check_creds = [] for cred_input_id, cred_id, _check_io_id in cred_input_rows: cred = next(filter(lambda c: c.id == cred_id, credentials)) check_creds.append(cred) # Build check IO expected = json.loads(expected) check_io = CheckIO(check_io_id, poll_input, expected, check_creds) # Update link from credential to this check IO for cred in check_creds: cred.check_io = check_io if check_id not in check_ios: check_ios[check_id] = [] check_ios[check_id].append(check_io) return check_ios
def load_credentials(self, teams, domains): """ Load credentials from the database. Arguments: teams (Dict(int->Team)): Mapping of team IDs to Teams to associate credentials with domains (List(Domain)): List of domains to associate credentials with Returns: List(Credential): List of credentials """ creds = [] cred_rows = db.getall('credential') for cred_id, username, password, team_id, check_id, domain_name, is_default in cred_rows: team = next(filter(lambda t: t.id == team_id, teams)) domain_lst = list(filter(lambda d: d.fqdn == domain_name, domains)) if len(domain_lst) == 0: domain = None else: domain = domain_lst[0] cred = Credential(cred_id, username, password, team, domain, is_default) creds.append(cred) return creds
def show(ircsock, channel): """ Show current set of tickets """ tickets = db.getall(ticket_type='active') sendmsg(ircsock, channel, "Current available tickets:") for ticket in tickets: show_one(ircsock, channel, ticket)