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)

            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. 3
0
	def getBestEvent(self, filename='events.json'):
		"""Returns the event most relevant to this user's interests."""
		if filename not in [f for f in os.listdir('.') if os.path.isfile(f)]:
			raise IOError('Error: events file ' + filename + ' not found.')
		data = json.load(open(filename))
		best_event = Event()
		best_score = 0
		for event in data['events']:
			iter_event = Event()
			# The declarations are split to keep the Item __init__ method for automatically calling the API to populate the model.
			iter_event.description = event['description']
			iter_event.name = event['name']
			iter_event.model = ConceptModel(model=event['model']['concepts'], maturity=1)
			iter_event.starttime = event['starttime']
			iter_event.endtime = event['endtime']
			iter_event.location = event['location']
			iter_event.picture = event['picture']
			iter_event.name = event['name']
			iter_event.url = event['url']
			score = best_event.compareTo(iter_event)
			if score >= best_score:
				# print(self.exceptions)
				if iter_event.name not in self.exceptions:
					best_event = iter_event
					best_score = score
		return best_event
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:
            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. 6
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. 7
0
  def GetSingleEvent(self, eventLandingPage):
    eventLandingPage = self.urlify(eventLandingPage)

    self.page = requests.get(eventLandingPage)
    eventTree = html.fromstring(self.page.text)

    new_event = Event()
    new_event.source = eventLandingPage.encode('utf-8')
    new_event.name = self.multipleXPaths(self.eventName_xpath, eventTree, 'name')
    new_event.location += self.multipleXPaths(self.eventLocation_xpath, eventTree, 'location')
    new_event.description = self.multipleXPaths(self.eventDescription_xpath, eventTree, 'description')
    new_event.datetime  = self.multipleXPaths(self.eventDateTime_xpath, eventTree, 'datetime')
    new_event.price = self.multipleXPaths(self.eventPrice_xpath, eventTree, 'price')
    new_event.imagePath = self.multipleXPaths(self.eventImage_xpath, eventTree, 'imagePath')
    new_event.imagePath = self.urlify(new_event.imagePath)
    new_event.dump = SiteText(eventLandingPage).gettext()

    new_event.cleanContent()


    # print (new_event)
    # print (new_event.name), "             name"
    # print (new_event.location), "             location"
    # print (new_event.description), "             description"
    # print (new_event.datetime), "             datetime"  
    # print (new_event.price), "             price"
    # print (new_event.imagePath), "             imagePath"


    return new_event
Esempio n. 8
0
    async def _set_description(self,
                               ctx: Context,
                               event: Event,
                               description: str = ""):
        if description and description[0] == '"' and description[-1] == '"':
            # Strip quotes from description
            description = description[1:-1]

        # Change description, update event
        event.description = description
        await self._update_event(event)
        if description:
            await ctx.send("Description \"{}\" set for operation {}".format(
                event.description, event))
        else:
            await ctx.send(
                "Description cleared from operation {}".format(event))
Esempio n. 9
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. 10
0
 def parseOneJson(self, obj):
   count = 0;
   if ((obj[self.eventResults] is not None) and (len(obj[self.eventResults])>0)):
     for result in obj[self.eventResults]:
       count += 1
       sys.stdout.write("\rGetting " + str(count) + " of " + str(len(obj[self.eventResults])))
       sys.stdout.flush()
       event = Event()
       event.name = self.checkIfList(self.eventName, result)
       event.location = self.checkIfList(self.location, result)
       event.description = self.checkIfList(self.description, result)
       event.datetime = self.checkIfList(self.eventTime, result)
       event.price = self.checkIfList(self.price, result)
       event.imagePath = self.checkIfList(self.image, result)
       event.dump = self.checkIfList(self.description, result)
       event.forceStr()
       self.allEvents.append(event)
     print "\n"
     return True
   else:
     return False
Esempio n. 11
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)))