Esempio n. 1
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            event = Event()
            event.service = self.name
            event.ttl = self.ttl * self.ttl_multiplier
            event.host = self.host
            event.tags = self.tags
            event.attributes = self.attributes

            output, attributes = self.parse_nagios_output(stdout)
            event.description = "Note: %s\nCommand: %s\nOutput: %s\n" % (self.note, self.raw_command, output)

            if returncode in self.exitcodes:
                event.state = self.exitcodes[returncode]
            else:
                event.state = 'unknown'

            if attributes:
                if 'metric' in self.config and self.config['metric'] in attributes:
                    metric_key = self.config['metric']
                else:
                    metric_key = attributes.keys()[0]

                event.attributes.update(attributes)
                event.metric = float(NUMERIC_REGEX.match(attributes[metric_key]).group(1))

            self.events.append(event)
        except Exception as e:
            log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 2
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            event = Event()
            event.service = self.name
            event.ttl = self.ttl * self.ttl_multiplier
            event.host = self.host
            event.tags = self.tags
            event.attributes = self.attributes

            output, attributes = self.parse_nagios_output(stdout)
            event.description = "Note: %s\nCommand: %s\nOutput: %s\n" % (self.note, self.raw_command, output)

            if returncode in self.exitcodes:
                event.state = self.exitcodes[returncode]
            else:
                event.state = 'unknown'

            if attributes:
                if 'metric' in self.config and self.config['metric'] in attributes:
                    metric_key = self.config['metric']
                else:
                    metric_key = attributes.keys()[0]

                event.attributes.update(attributes)
                event.metric = float(NUMERIC_REGEX.match(attributes[metric_key]).group(1))

            self.events.append(event)
        except Exception as e:
            log.exception("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 3
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            try:
                results = json.loads(stdout)
            except Exception as e:
                log.error("Failed to parse JSON. '%s':\n%s" % (self.name, str(e)))
                return

            for result in results:
                for field in ['service', 'state', 'description', 'metric']:
                    if field not in result:
                        log.error("Event missing field '%s'" % (field))
                        continue

                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.attributes = self.attributes

                if "attributes" in result:
                    event.attributes.update({self.attrprefix + name: result["attributes"][name] for name in result["attributes"]})

                event.service = result['service']
                event.state = result['state']
                event.metric = result['metric']
                event.description = "%s\n%s" % (self.note, result['description'])
                self.events.append(event)
        except Exception as e:
            log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 4
0
    def join(self):
        try:
            json_result = self.q.get(timeout=(self.ttl * 0.3))
            self.proc.join()

            log.debug('CloudKickTask: Processing %s metrics' % (len(json_result['metrics'])))
            for metric in json_result['metrics']:
                note = metric['note'] if 'note' in metric else self.note
                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.service = metric['name']
                event.state = metric['state']
                event.metric = metric['value']
                event.description = "%s\nWarn threshold: %s, Error threshold: %s" % (note,
                                                                                     metric['warn_threshold'],
                                                                                     metric['error_threshold'])
                if 'attributes' in metric:
                    event.attributes = metric['attributes']

                self.events.append(event)
        except Exception as e:
            log.error("Exception joining CloudKickTask '%s'\n%s" % (self.name, traceback.format_exc()))
            self.locked = False
Esempio n. 5
0
    def join(self):
        try:
            json_result = self.q.get(timeout=(self.ttl * 0.3))
            self.proc.join()

            log.debug('CloudKickTask: Processing %s metrics' % (len(json_result['metrics'])))
            for metric in json_result['metrics']:
                note = metric['note'] if 'note' in metric else self.note
                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.service = metric['name']
                event.state = metric['state']
                event.metric = metric['value']
                event.description = "%s\nWarn threshold: %s, Error threshold: %s" % (note,
                                                                                     metric['warn_threshold'],
                                                                                     metric['error_threshold'])
                if 'attributes' in metric:
                    event.attributes = metric['attributes']

                self.events.append(event)
        except Exception as e:
            log.exception("Exception joining CloudKickTask '%s'\n%s" % (self.name, traceback.format_exc()))
            self.locked = False
Esempio n. 6
0
def scrape_dance_cal(keys_from_spreadsheet):
	"""Scrapes dancecal.com. and returns an event instance
	that includes name, start date, end date, country, city, url,
	dance styles, teachers, status, key, and an obsolete value"""
	soup = get_soup(URL_DC)
	for event_div in soup.findAll('div', {'class' : 'DCListEvent'}):
		name = None
		event = Event()
		for span in event_div.findAll('span'):

			if 'DCListName' in span['class']:
				name = span.text.strip()
			print(name)
			if name == None:
				continue
			elif name.lower() in event_name_list:
				# checks to see if the event name already exists in the instance list
				# If it does, it skips it
				continue
			else:
				# This means the event does not already exist in the instance list
				# and will be added
				if 'DCListName' in span['class']:
					event.name = span.text.strip()
					for a_tag in span.findAll('a', href=True):
						event.url = a_tag['href']
				if 'DCEventInfoDate' in span['class']:
					event.start_date = parse(span.text)
					# Now need to guess what the end_date will be since this site does not provide it
					# I'm going to assume that events will tend to end on a Sunday
					# For example, if an event starts on a friday, I will make it's end-date two days later. 
					weekday = event.start_date.weekday()
					gap = datetime.timedelta(days = 6 - weekday)
					event.end_date = event.start_date + gap
				if 'DCEventInfoWhere' in span['class']:
					location_list = span.text.replace(':',',').split(',')
					if len(location_list) == 3:
						event.country = location_list[2].strip()
						event.city = location_list[1].strip()
					if len(location_list) == 4:
						event.country = location_list[3].strip()
						event.state = location_list[2].strip()
						event.city = location_list[1].strip()
				if 'DCEventInfoDances' in span['class']:
					event.dance_styles = span.text.split(': ')[1].lower().strip()
				if 'DCEventInfoTeachers' in span['class']:
					event.teachers = str(span).replace('<br/>', '$').replace(':', '$').replace('</i>', '$').replace('|', 'and').split('$')[1:-1]
				if 'DCEventInfoDesc' in span['class']:
					event.details = span.text.strip()
				if 'DCEventInfoBands' in span['class']:
					event.bands = span.text.split(':')[1].strip()
		if event.name == None:
			pass
		else:
			event.key = create_key(event)
			event_list = append_to_event_list(event, event.key, keys_from_spreadsheet)
	return event_list
Esempio n. 7
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            try:
                results = json.loads(stdout)
            except Exception as e:
                log.error("Failed to parse JSON. '%s':\n%s" % (self.name, str(e)))
                return

            for result in results:
                for field in ['service', 'state', 'description', 'metric']:
                    if field not in result:
                        log.error("Event missing field '%s'" % (field))
                        continue

                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.attributes = dict(self.attributes)

                if 'host' in result and result['host'] is not None:
                    event.host = result['host']
                else:
                    event.host = self.host

                if 'tags' in result and result['tags'] is not None:
                    event.tags = self.tags.union(result['tags'])
                else:
                    event.tags = self.tags

                if "attributes" in result:
                    attributes = result["attributes"]
                    event.attributes.update(dict((self.clean_attribute_name(key), attributes[key]) for key in attributes))

                event.service = result['service']
                event.state = result['state']
                event.metric = result['metric']
                event.description = "%s\n%s" % (self.note, result['description'])
                self.events.append(event)
        except Exception as e:
            log.exception("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 8
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            try:
                results = json.loads(stdout)
            except Exception as e:
                log.error("Failed to parse JSON. '%s':\n%s" %
                          (self.name, str(e)))
                return

            for result in results:
                for field in ['service', 'state', 'description', 'metric']:
                    if field not in result:
                        log.error("Event missing field '%s'" % (field))
                        continue

                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.attributes = self.attributes

                if "attributes" in result:
                    event.attributes.update({
                        self.attrprefix + name: result["attributes"][name]
                        for name in result["attributes"]
                    })

                event.service = result['service']
                event.state = result['state']
                event.metric = result['metric']
                event.description = "%s\n%s" % (self.note,
                                                result['description'])
                self.events.append(event)
        except Exception as e:
            log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 9
0
def create_event_list():
    event_list = []
    for row_number, row in enumerate(
            utils.iter_worksheet(spreadsheet, 'Sheet1', header_row=1)):
        if row['key'] != '' and row['obsolete'] != '1' and row[
                'status'] != 'past':
            event = Event()
            event.key = row['key']
            event.name = row['name']
            event.start_date = parse(row['start date'])
            event.end_date = parse(row['end date'])
            event.city = row['city']
            event.state = row['state']
            event.country = row['country']
            event.dance_styles = row['dance styles']
            event.status = row['status']
            event.url = row['url']
            event.teachers = row['teachers']
            event.bands = row['bands']
            event.details = row['details']
            event.obsolete = row['obsolete']
            event.workshop_cost = get_cost(row, 'workshop cost')
            event.party_pass_cost = get_cost(row, 'party pass cost')
            event.distance = int(row['distance'])
            event.flight_cost = int(row['flight cost'])
            event.event_type = row['type']
            if row['currency'] == '':
                event.currency = 'USD'
            else:
                event.currency = row['currency']
            if row['driving time'] == '':
                event.driving_time = 99999
            else:
                event.driving_time = int(row['driving time'])
            event_list.append(event)
    return event_list