def create_and_link_comments(self, raw_objects, all_obj):
        #first service
        for obj_cfg in raw_objects['servicecomment']:
            #print "Managing", obj_cfg
            host_name = obj_cfg['host_name']
            service_description = obj_cfg['service_description']
            srv = all_obj['service'].find_srv_by_name_and_hostname(
                host_name, service_description)
            #print "Find my service", srv
            if srv is not None:
                cmd = Comment(srv, to_bool(obj_cfg['persistent']),
                              obj_cfg['author'], obj_cfg['comment_data'], 1,
                              int(obj_cfg['entry_type']),
                              int(obj_cfg['source']),
                              to_bool(obj_cfg['expires']),
                              int(obj_cfg['expire_time']))
                #print "Created cmd", cmd
                srv.add_comment(cmd)

    #then hosts
        for obj_cfg in raw_objects['hostcomment']:
            #print "Managing", obj_cfg
            host_name = obj_cfg['host_name']
            hst = all_obj['host'].find_by_name(host_name)
            #print "Find my host", hst
            if hst is not None:
                cmd = Comment(hst, to_bool(obj_cfg['persistent']),
                              obj_cfg['author'], obj_cfg['comment_data'], 1,
                              int(obj_cfg['entry_type']),
                              int(obj_cfg['source']),
                              to_bool(obj_cfg['expires']),
                              int(obj_cfg['expire_time']))
                #print "Created cmd", cmd
                hst.add_comment(cmd)
예제 #2
0
 def add_automatic_comment(self):
     if self.fixed is True:
         text = (
             "This %s has been scheduled for fixed downtime from %s to %s. "
             "Notifications for the %s will not be sent out during that time period." % (
                 self.ref.my_type,
                 time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.start_time)),
                 time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.end_time)),
                 self.ref.my_type)
         )
     else:
         hours, remainder = divmod(self.duration, 3600)
         minutes, seconds = divmod(remainder, 60)
         text = ("This %s has been scheduled for flexible downtime starting between %s and %s "
                 "and lasting for a period of %d hours and %d minutes. "
                 "Notifications for the %s will not be sent out during that time period." % (
                     self.ref.my_type,
                     time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.start_time)),
                     time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.end_time)),
                     hours, minutes, self.ref.my_type)
                 )
     if self.ref.my_type == 'host':
         comment_type = 1
     else:
         comment_type = 2
     c = Comment(self.ref, False, "(Nagios Process)", text, comment_type, 2, 0, False, 0)
     self.comment_id = c.id
     self.extra_comment = c
     self.ref.add_comment(c)
예제 #3
0
파일: item.py 프로젝트: zxahu/shinken
 def acknowledge_problem(self,
                         sticky,
                         notify,
                         persistent,
                         author,
                         comment,
                         end_time=0):
     if self.state != self.ok_up:
         if notify:
             self.create_notifications('ACKNOWLEDGEMENT')
         self.problem_has_been_acknowledged = True
         if sticky == 2:
             sticky = True
         else:
             sticky = False
         a = Acknowledge(self,
                         sticky,
                         notify,
                         persistent,
                         author,
                         comment,
                         end_time=end_time)
         self.acknowledgement = a
         if self.my_type == 'host':
             comment_type = 1
         else:
             comment_type = 2
         c = Comment(self, persistent, author, comment, comment_type, 4, 0,
                     False, 0)
         self.add_comment(c)
         self.broks.append(self.get_update_status_brok())