Exemplo n.º 1
0
    def sanitize(self, event):
        #if only id, this is a clear event.
        if len(event.keys()) == 1:
            return [event]
        # if only one key (id) -> clearing event. No use to
        # add sanitized stuff

        event = self._translate_keys(event)

        event.add('sector','comm')
        event.add('service', 'data') 
        event.add('type', 'interruption')
        event.add('organization', 'Elion')

        if event.value('county',False):
            event.add('area',event.value('county'))

        if event.contains('service name'):
            event.add('subtype',event.value('service name'))
        else:
            event.add('subtype', 'undefined')

        started = event.value('started', False)
        if started:
            start_seconds = timeconversion.datetime2seconds(started)
            start_iso = timeconversion.seconds2iso(start_seconds)
            event.add('start', str(start_iso))


        planned_end = event.value('planned end', '')
        if planned_end == '':
            event.clear('planned end')
            event.add('planned end', 'unknown')
        else:
            end_seconds  = timeconversion.datetime2seconds(planned_end)
            end_iso = timeconversion.seconds2iso(end_seconds)
            if end_iso == None:
                self.log.warning('Could not convert %s to seconds.' % (planned_end))
            else:
                event.add('end',end_iso)
                event.clear('planned end')
                event.add('planned end',end_iso)

        try:
            problem = self._get_problem(event)
            event.add('problem', problem)
            event.add('status', problem)
        except ValueError, e:
            self.log.warning('Could not analyze problem: %s' % (e))
Exemplo n.º 2
0
    def sanitize(self, event):
        #if only id, this is a clear event.
        if len(event.keys()) == 1:
            return [event]
        # if only one key (id) -> clearing event. No use to
        # add sanitized stuff

        event = self._translate_keys(event)

        event.add('sector', 'comm')
        event.add('service', 'data')
        event.add('type', 'interruption')
        event.add('organization', 'Elion')

        if event.value('county', False):
            event.add('area', event.value('county'))

        if event.contains('service name'):
            event.add('subtype', event.value('service name'))
        else:
            event.add('subtype', 'undefined')

        started = event.value('started', False)
        if started:
            start_seconds = timeconversion.datetime2seconds(started)
            start_iso = timeconversion.seconds2iso(start_seconds)
            event.add('start', str(start_iso))

        planned_end = event.value('planned end', '')
        if planned_end == '':
            event.clear('planned end')
            event.add('planned end', 'unknown')
        else:
            end_seconds = timeconversion.datetime2seconds(planned_end)
            end_iso = timeconversion.seconds2iso(end_seconds)
            if end_iso == None:
                self.log.warning('Could not convert %s to seconds.' %
                                 (planned_end))
            else:
                event.add('end', end_iso)
                event.clear('planned end')
                event.add('planned end', end_iso)

        try:
            problem = self._get_problem(event)
            event.add('problem', problem)
            event.add('status', problem)
        except ValueError, e:
            self.log.warning('Could not analyze problem: %s' % (e))
Exemplo n.º 3
0
    def sanitize(self, event):
        # if only one key (id) -> clearing event. No use to
        # add sanitized stuff

        # Return a list of events here. The list can contain 0-n events.
        descr = event.value('decription', False)
        if descr:
            event.add('description', descr)
            event.clear('decription')

        time_sec = event.value('time', False)
        if time_sec:
            event.clear('time')
            event.add('time', timeconversion.seconds2iso(time_sec))
        return [event]
Exemplo n.º 4
0
    def sanitize(self, event):
        # if only one key (id) -> clearing event. No use to
        # add sanitized stuff

        # Return a list of events here. The list can contain 0-n events.
        descr = event.value('decription', False)
        if descr:
            event.add('description', descr)
            event.clear('decription')

        time_sec = event.value('time', False)
        if time_sec:
            event.clear('time')
            event.add('time', timeconversion.seconds2iso(time_sec))
        return [event]
Exemplo n.º 5
0
    def sanitize(self, event):
        # if only one key (id) -> clearing event. No use to
        # add sanitized stuff
        if len(event.keys()) < 2:
            return [event]

        # variables for description
        now_iso = timeconversion.seconds2iso(time.time())

        event.add('service', 'weather')
        types = event.values('wtype')

        for type in types:
            event.add('type', self._get_type(type))

        problems = event.values('level')
        for problem in problems:
            problemvalue = self._get_problem(problem)
            event.add('problem', 'true')
            event.add('status', str(problemvalue))

        generic_level = event.value('generic_level', False)
        if generic_level == 'lvlbox1.gif':
            event.add('status', '0')

        # Return a list of events here. The list can contain 0-n events.
        event.clear(
            'description')  # source has in some cases also 'description' tag
        status = event.value('type', None)
        if status == None:
            status = 'no warnings'

        description = '%s - %s - %s - %s' % \
            (now_iso,
             event.value('organization',''),
             event.value('area',''),
             status)
        event.add('description', description)

        return [event]
Exemplo n.º 6
0
    def get_event(self, user):
        status = user.GetStatus()
        update = status.GetCreatedAtInSeconds()
        name = user.name.lower()
        followers_count = user.GetFriendsCount()
        statuses_count = user.GetStatusesCount()
        event = events.Event()
        event.add('user', user.name.lower())
        now = timeconversion.local_iso()
        event = blogparse(event, status.text)
        event.add('description',
                  "%s - %s - %s" % (now, name, status.text.lower()))
        event.add('type', 'microblog')
        event.add('subtype', 'twitter')
        event.add('followers', unicode(followers_count))
        event.add('statuses_count', unicode(statuses_count))
        event.add('src', user.name.lower())
        event.add('dst', 'followers')

        event.add('id', id.create_id(event, 'user'))
        event.add('start', timeconversion.seconds2iso(update))
        return event
Exemplo n.º 7
0
    def sanitize(self, event):
        # if only one key (id) -> clearing event. No use to
        # add sanitized stuff
        if len(event.keys()) < 2:
            return [event]

        # variables for description
        now_iso = timeconversion.seconds2iso(time.time())

        event.add('service','weather')
        types = event.values('wtype')

        for type in types:
            event.add('type',self._get_type(type))

        problems = event.values('level')
        for problem in problems:
            problemvalue = self._get_problem(problem)
            event.add('problem','true')
            event.add('status',str(problemvalue))

        generic_level = event.value('generic_level',False)
        if generic_level == 'lvlbox1.gif':
            event.add('status','0')
                
        # Return a list of events here. The list can contain 0-n events.
        event.clear('description') # source has in some cases also 'description' tag
        status = event.value('type', None)
        if status == None:
            status = 'no warnings'

        description = '%s - %s - %s - %s' % \
            (now_iso, 
             event.value('organization',''),
             event.value('area',''),
             status)
        event.add('description', description)

        return [event]
Exemplo n.º 8
0
    def get_event(self,user):
        status = user.GetStatus()
        update = status.GetCreatedAtInSeconds()
        name = user.name.lower()
        followers_count = user.GetFriendsCount()
        statuses_count = user.GetStatusesCount()
        event = events.Event()
        event.add('user',user.name.lower())
        now = timeconversion.local_iso()
        event = blogparse(event, status.text)
        event.add('description', "%s - %s - %s" % (now, name, status.text.lower()))
        event.add('type', 'microblog')
        event.add('subtype','twitter')
        event.add('followers',unicode(followers_count))
        event.add('statuses_count', unicode(statuses_count))
        event.add('src',user.name.lower())
        event.add('dst','followers')
        
        

        event.add('id',id.create_id(event,'user'))
        event.add('start', timeconversion.seconds2iso(update))
        return event
Exemplo n.º 9
0
        inutilization = event.value('inutilization','')
        oututilization = event.value('oututilization','')
        try:
            inutilization_value = float(inutilization)
            oututilization_value = float(oututilization)
        except ValueError, e:
            pass
        else:
            value = max([inutilization_value,oututilization_value])
            problem = self._get_problem(value)
            if problem > 0:
                event.add('problem',unicode(problem))
            event.add('status', unicode(problem))

        isotime = timeconversion.seconds2iso(time.time())

        event.add("asset", "port: %s" % (event.value('customer','')))
        customer = event.value('customer','')
        
        description = '%s - %s - utilization: in/out %%: %s/%s - %s ' % \
            (isotime,event.value('organization',''),
             inutilization, oututilization, customer)
        event.add("description", description)

        # Return a list of events here. The list can contain 0-n events.
        return [event]
    
if __name__ == "__main__":
    # Execute the sanitizer bot based on the command line options.
    TixSanitizer.from_command_line().execute()
Exemplo n.º 10
0
class EmhiEESanitizer(sanitizer.Sanitizer):
    # .sanitize(event) is the hook method for sanitizing events. This
    # is the only method you have to implement to create a basic
    # normalizer, sanitizer, modifier or filter.
    def sanitize(self, event):
        #if only id, this is a clear event.
        if len(event.keys()) == 1:
            return [event]
        # if only one key (id) -> clearing event. No use to
        # add sanitized stuff

        event = self._translate_keys(event)

        event.add('sector', 'comm')
        event.add('service', 'data')
        event.add('type', 'interruption')
        event.add('organization', 'Elion')

        if event.value('county', False):
            event.add('area', event.value('county'))

        if event.contains('service name'):
            event.add('subtype', event.value('service name'))
        else:
            event.add('subtype', 'undefined')

        started = event.value('started', False)
        if started:
            start_seconds = timeconversion.datetime2seconds(started)
            start_iso = timeconversion.seconds2iso(start_seconds)
            event.add('start', str(start_iso))

        planned_end = event.value('planned end', '')
        if planned_end == '':
            event.clear('planned end')
            event.add('planned end', 'unknown')
        else:
            end_seconds = timeconversion.datetime2seconds(planned_end)
            end_iso = timeconversion.seconds2iso(end_seconds)
            if end_iso == None:
                self.log.warning('Could not convert %s to seconds.' %
                                 (planned_end))
            else:
                event.add('end', end_iso)
                event.clear('planned end')
                event.add('planned end', end_iso)

        try:
            problem = self._get_problem(event)
            event.add('problem', problem)
            event.add('status', problem)
        except ValueError, e:
            self.log.warning('Could not analyze problem: %s' % (e))

        description = event.value('description', '')

        subtype = event.value('subtype', False)
        if subtype:
            subtype = re.sub('ELION SEIRE \*\*\* ', '', subtype)
            event.clear('subtype')
            event.add('subtype', subtype)

        status = self._get_status(event)

        description = "%s - %s - %s" % (timeconversion.seconds2iso(
            time.time()), event.value('organization', ''), description)

        event.clear('description')
        event.add('description', description)

        # Return a list of events here. The list can contain 0-n events.
        return [event]
Exemplo n.º 11
0
    def sanitize(self, event):
        # if only one key (id) -> clearing event.
        if len(event.keys()) < 2:
            return [event]

        host = event.value('host', '')
        event.clear('host')
        event.add('asset', host)
        match = re.search("^(.*?)-.*?.aso.ee", host)

        if match:
            area = match.group(1)
            area = area[0].upper() + area[1:]
            event.add('area', area)
            event = geo.add_geo_if_available(area, event)
            if event.value('latitude', False) == False:
                self.log.warning('No geocoordinates for %s.' % (area))

        state = event.value('state', None)
        if state != None:
            normalize_status = {'critical': 'alert'}
            if state in normalize_status:
                state = normalize_status[state]
            event.clear('state')
            event.add('status', state)

        if event.contains('address'):
            addr = event.value('address')
            event.add('ip', addr)

        datetime = event.value('date/time', 'unknown')
        nagios_converts_t = "|".join(nagios_date_convert.keys())

        nagios_converts = re.compile(nagios_converts_t)
        if nagios_converts.search(datetime):
            for key in nagios_date_convert.keys():
                if re.search(key, datetime):
                    datetime = re.sub(key, nagios_date_convert[key], datetime)

        if datetime != 'unknown':
            seconds = timeconversion.datetime2seconds(datetime)
        else:
            seconds = time.time()
        isotime = timeconversion.seconds2iso(seconds)
        if isotime == None:
            isotime = "unknown"

        event.add('start', isotime)
        #we don't have data for estimating the level of problem, setting all to 10
        event.add('problem', 'true')
        event.add('status', '10')

        subtype = event.value('type', False)
        if subtype:
            event.add('subtype', subtype)
            event.clear('type')
        event.add('type', 'interruption')

        event.add('sector', 'comm')
        event.add('service', 'data')

        now_iso = timeconversion.seconds2iso(time.time())
        description = '%s - %s - %s: %s clients' % \
            (now_iso, event.value('organization',''),
             event.value('asset','')
             , event.value('affected_clients', '?'))

        event.add('description', description)
        return [event]
Exemplo n.º 12
0
        inutilization = event.value('inutilization', '')
        oututilization = event.value('oututilization', '')
        try:
            inutilization_value = float(inutilization)
            oututilization_value = float(oututilization)
        except ValueError, e:
            pass
        else:
            value = max([inutilization_value, oututilization_value])
            problem = self._get_problem(value)
            if problem > 0:
                event.add('problem', unicode(problem))
            event.add('status', unicode(problem))

        isotime = timeconversion.seconds2iso(time.time())

        event.add("asset", "port: %s" % (event.value('customer', '')))
        customer = event.value('customer', '')

        description = '%s - %s - utilization: in/out %%: %s/%s - %s ' % \
            (isotime,event.value('organization',''),
             inutilization, oututilization, customer)
        event.add("description", description)

        # Return a list of events here. The list can contain 0-n events.
        return [event]


if __name__ == "__main__":
    # Execute the sanitizer bot based on the command line options.
Exemplo n.º 13
0
    def sanitize(self, event):
        # if only one key (id) -> clearing event.
        if len(event.keys()) < 2:
            return [event]

        host = event.value('host','')
        event.clear('host')
        event.add('asset',host)
        match = re.search("^(.*?)-.*?.aso.ee",host)

        if match:
            area = match.group(1)
            area = area[0].upper() + area[1:]
            event.add('area', area)
            event = geo.add_geo_if_available(area,event)
            if event.value('latitude', False) == False:
                self.log.warning('No geocoordinates for %s.' % (area))

        state = event.value('state',None)
        if state != None:
            normalize_status = {'critical':'alert'}
            if state in normalize_status:
                state = normalize_status[state]
            event.clear('state')
            event.add('status',state)

        if event.contains('address'):
            addr = event.value('address')
            event.add('ip',addr)

        datetime = event.value('date/time','unknown')
        nagios_converts_t = "|".join(nagios_date_convert.keys())


        nagios_converts = re.compile(nagios_converts_t)
        if nagios_converts.search(datetime):
            for key in nagios_date_convert.keys():
                if re.search(key,datetime):
                    datetime = re.sub(key,nagios_date_convert[key],datetime)

        if datetime != 'unknown':
            seconds = timeconversion.datetime2seconds(datetime)
        else:
            seconds = time.time()
        isotime = timeconversion.seconds2iso(seconds)
        if isotime == None:
            isotime = "unknown"

        event.add('start',isotime)
        #we don't have data for estimating the level of problem, setting all to 10
        event.add('problem', 'true')
        event.add('status', '10')

        subtype = event.value('type',False)
        if subtype:
            event.add('subtype', subtype)
            event.clear('type')
        event.add('type', 'interruption')

        event.add('sector','comm')
        event.add('service', 'data')

        now_iso = timeconversion.seconds2iso(time.time())
        description = '%s - %s - %s: %s clients' % \
            (now_iso, event.value('organization',''),
             event.value('asset','')
             , event.value('affected_clients', '?'))

        event.add('description', description)
        return [event]