• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.safe_print函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shinken.util.safe_print函数的典型用法代码示例。如果您正苦于以下问题:Python safe_print函数的具体用法?Python safe_print怎么用?Python safe_print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了safe_print函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: manage_check_ping_command

def manage_check_ping_command(elt):
    safe_print('Get check_ping perfdata of', elt.get_full_name())
    p = PerfDatas(elt.perf_data)
    if not 'rta' in p:
        print "No rta in p"
        return None

    m = p['rta']
    v = m.value
    crit = m.critical
    if not v or not crit:
        print "No value, I bailout"
        return None

    # Percent of ok should be the log of time versus max/2
    pct = get_logarithmic(v, crit/2)
    # Now get the color
    # OK : #6f2 (102,255,34) green
    # Warning : #f60 (255,102,0) orange
    # Crit : #ff0033 (255,0,51)
    base_color = {0 : (102,255,34), 1 : (255,102,0), 2 : (255,0,51)}
    state_id = get_stateid(elt)
    color = base_color.get(state_id, (179,196,255))
    s_color = 'RGB(%d,%d,%d)' % color    

    lnk = '#'
    metrics = [(s_color, pct), ('white', 100-pct)]
    title = '%sms' % v
    print "HTTP: return", {'lnk' : lnk, 'metrics' : metrics, 'title' : title}
    return {'lnk' : lnk, 'metrics' : metrics, 'title' : title}
开发者ID:bs-github,项目名称:shinken,代码行数:30,代码来源:perfdata_guess.py


示例2: is_correct

    def is_correct(self):
        # we are ok at the begining. Hope we still ok at the end...
        r = True
        # Some class do not have twins, because they do not have names
        # like servicedependencies
        twins = getattr(self, 'twins', None)
        if twins is not None:
            # Ok, look at no twins (it's bad!)
            for id in twins:
                i = self.items[id]
                safe_print("Error: the", i.__class__.my_type, i.get_name(), "is duplicated from", i.imported_from)
                r = False

        # Then look if we have some errors in the conf
        # Juts print warnings, but raise errors
        for err in self.configuration_warnings:
            print err

        for err in self.configuration_errors:
            print err
            r = False

        # Then look for individual ok
        for i in self:
            if not i.is_correct():
                n = getattr(i, 'imported_from', "unknown")
                safe_print("Error: In", i.get_name(), "is incorrect ; from", n)
                r = False        
        
        return r
开发者ID:pydubreucq,项目名称:shinken,代码行数:30,代码来源:item.py


示例3: get_dep_graph_struct

    def get_dep_graph_struct(self, elt, levels=3):
        t = elt.__class__.my_type
        # We set the values for webui/plugins/depgraph/htdocs/js/eltdeps.js
        # so a node with important data for rendering
        # type = custom, business_impact and img_src.
        d = {
            "id": elt.get_dbg_name(),
            "name": elt.get_dbg_name(),
            "data": {"$type": "custom", "business_impact": elt.business_impact, "img_src": self.get_icon_state(elt)},
            "adjacencies": [],
        }

        # Set the right info panel
        d["data"][
            "infos"
        ] = r"""%s <h2 class="%s"><img style="width: 64px; height:64px" src="%s"/> %s: %s</h2>
                   <p>since %s</p>
                   <div style="float:right;"> <a href="%s">%s</a></div>""" % (
            '<img src="/static/img/icons/star.png" alt="star">' * (elt.business_impact - 2),
            elt.state.lower(),
            self.get_icon_state(elt),
            elt.state,
            elt.get_full_name(),
            self.print_duration(elt.last_state_change, just_duration=True, x_elts=2),
            self.get_link_dest(elt),
            self.get_button("Go to details", img="/static/images/search.png"),
        )

        d["data"]["elt_type"] = elt.__class__.my_type
        d["data"]["is_problem"] = elt.is_problem
        d["data"]["state_id"] = elt.state_id

        safe_print("ELT:%s is %s" % (elt.get_full_name(), elt.state))
        if elt.state in ["OK", "UP", "PENDING"]:
            d["data"]["circle"] = "none"
        elif elt.state in ["DOWN", "CRITICAL"]:
            d["data"]["circle"] = "red"
        elif elt.state in ["WARNING", "UNREACHABLE"]:
            d["data"]["circle"] = "orange"
        else:
            d["data"]["circle"] = "none"

        # Now put in adj our parents
        for p in elt.parent_dependencies:
            pd = {
                "nodeTo": p.get_dbg_name(),
                "data": {"$type": "line", "$direction": [elt.get_dbg_name(), p.get_dbg_name()]},
            }

            # Naive way of looking at impact
            if elt.state_id != 0 and p.state_id != 0:
                pd["data"]["$color"] = "Tomato"
            # If OK, show host->service as a green link
            elif elt.__class__.my_type != p.__class__.my_type:
                pd["data"]["$color"] = "PaleGreen"
            d["adjacencies"].append(pd)

        # The sons case is now useful, it will be done by our sons
        # that will link us
        return d
开发者ID:rsauvatinet,项目名称:shinken,代码行数:60,代码来源:helper.py


示例4: get_page

def get_page():
    # First we look for the user sid
    # so we bail out if it's a false one
    user = app.get_user_auth()

    if not user:
        app.bottle.redirect("/user/login")

    all_imp_impacts = app.datamgr.get_important_elements()
    all_imp_impacts.sort(hst_srv_sort)
    #all_imp_impacts.sort(hst_srv_sort)

    #all_imp_impacts = app.datamgr.get_services() #important_elements()

    impacts = []
    for imp in all_imp_impacts:
        safe_print("FIND A BAD SERVICE IN IMPACTS", imp.get_dbg_name())
        d = {'name': imp.get_full_name().encode('utf8', 'ignore'),
             "title": "My Image 3", "thumb": "/static/images/state_flapping.png", "zoom": "/static/images/state_flapping.png",
             "html": get_div(imp)}
        impacts.append(d)

    # Got in json format
    #j_impacts = json.dumps(impacts)
    #print "Return impact in json", j_impacts
    all_pbs = app.datamgr.get_all_problems()
    now = time.time()
    # Get only the last 10min errors
    all_pbs = [pb for pb in all_pbs if pb.last_state_change > now - 600]
    # And sort it
    all_pbs.sort(hst_srv_sort)  # sort_by_last_state_change)

    return {'app': app, 'user': user, 'impacts': impacts, 'problems': all_pbs}
开发者ID:GPCsolutions,项目名称:mod-webui,代码行数:33,代码来源:flow.py


示例5: get_page

def get_page():
    # First we look for the user sid
    # so we bail out if it's a false one
    user = app.get_user_auth()

    if not user:
        redirect("/user/login")
    

    all_imp_impacts = app.datamgr.get_services()#important_elements()
    #all_imp_impacts.sort(hst_srv_sort)

    impacts = []
    for imp in all_imp_impacts:
        safe_print("FIND A BAD SERVICE IN IMPACTS", imp.get_dbg_name())
        d = {'name' : imp.get_full_name().encode('utf8', 'ignore'),
             "title": "My Image 3", "thumb": "/static/images/state_flapping.png", "zoom": "/static/images/state_flapping.png",
             "html" : get_div(imp)}
        impacts.append(d)
    
    # Got in json format
    #j_impacts = json.dumps(impacts)
#    print "Return impact in json", j_impacts

    return {'app' : app, 'user' : user, 'impacts' : impacts}
开发者ID:pydubreucq,项目名称:shinken,代码行数:25,代码来源:wall.py


示例6: manage_check_ping_command

def manage_check_ping_command(elt):
    safe_print('Get check_ping perfdata of', elt.get_full_name())
    p = PerfDatas(elt.perf_data)
    if not 'rta' in p:
        print "No rta in p"
        return None

    m = p['rta']
    v = m.value
    crit = m.critical
    if not v or not crit:
        print "No value, I bailout"
        return None

    # Pourcent of ok should be time/10s
    pct = 100 * (v / crit)
    # go to int
    pct = int(pct)
    # But at least 1%
    pct = max(1, pct)
    #And max to 100%
    pct = min(pct, 100)
    lnk = '#'
    metrics = [('#68f', pct), ('white', 100-pct)]
    title = '%sms' % v
    print "HTTP: return", {'lnk' : lnk, 'metrics' : metrics, 'title' : title}
    return {'lnk' : lnk, 'metrics' : metrics, 'title' : title}
开发者ID:pjjw,项目名称:shinken,代码行数:27,代码来源:perfdata_guess.py


示例7: all_done_linking

    def all_done_linking(self, inst_id):
        """In addition to the original all_done_linking our items will get sorted"""
        super(self.__class__, self).all_done_linking(inst_id)

        # now sort the item collections by name
        safe_print("SORTING HOSTS AND SERVICES")
        # First install a new attribute _id_heap, which holds the
        # item ids in sorted order
        setattr(self.services, '_id_heap', [(get_obj_full_name(v), k) for (k, v) in self.services.items.iteritems()])
        self.services._id_heap.sort(key=lambda x: x[0])
        setattr(self.hosts, '_id_heap', [(get_obj_full_name(v), k) for (k, v) in self.hosts.items.iteritems()])
        self.hosts._id_heap.sort(key=lambda x: x[0])
        setattr(self.contacts, '_id_heap', [(get_obj_full_name(v), k) for (k, v) in self.contacts.items.iteritems()])
        self.contacts._id_heap.sort(key=lambda x: x[0])
        setattr(self.servicegroups, '_id_heap', [(get_obj_full_name(v), k) for (k, v) in self.servicegroups.items.iteritems()])
        self.servicegroups._id_heap.sort(key=lambda x: x[0])
        setattr(self.hostgroups, '_id_heap', [(get_obj_full_name(v), k) for (k, v) in self.hostgroups.items.iteritems()])
        self.hostgroups._id_heap.sort(key=lambda x: x[0])
        setattr(self.contactgroups, '_id_heap', [(get_obj_full_name(v), k) for (k, v) in self.contactgroups.items.iteritems()])
        self.contactgroups._id_heap.sort(key=lambda x: x[0])
        # Then install a method for accessing the lists' elements in sorted order
        setattr(self.services, '__itersorted__', types.MethodType(itersorted, self.services))
        setattr(self.hosts, '__itersorted__', types.MethodType(itersorted, self.hosts))
        setattr(self.contacts, '__itersorted__', types.MethodType(itersorted, self.contacts))
        setattr(self.servicegroups, '__itersorted__', types.MethodType(itersorted, self.servicegroups))
        setattr(self.hostgroups, '__itersorted__', types.MethodType(itersorted, self.hostgroups))
        setattr(self.contactgroups, '__itersorted__', types.MethodType(itersorted, self.contactgroups))

        # Everything is new now. We should clean the cache
        self.cache.wipeout()
开发者ID:bs-github,项目名称:shinken,代码行数:30,代码来源:livestatus_regenerator.py


示例8: remove_twins

 def remove_twins(self):
     for id in self.twins:
         i = self.items[id]
         type = i.__class__.my_type
         safe_print('Warning: the', type, i.get_name(), 'is already defined.')
         del self.items[id] # bye bye
     # do not remove twins, we should look in it, but just void it
     self.twins = []
开发者ID:pydubreucq,项目名称:shinken,代码行数:8,代码来源:item.py


示例9: get_important_elements

 def get_important_elements(self):
     res = []
     # We want REALLY important things, so business_impact > 2, but not just IT elments that are
     # root problems, so we look only for config defined my_own_business_impact value too
     res.extend([s for s in self.rg.services if (s.business_impact > 2 and not 0 <= s.my_own_business_impact <= 2) ])
     res.extend([h for h in self.rg.hosts if (h.business_impact > 2 and not 0 <= h.my_own_business_impact <= 2)] )
     print "DUMP IMPORTANT"
     for i in res:
         safe_print(i.get_full_name(), i.business_impact, i.my_own_business_impact)
     return res
开发者ID:bs-github,项目名称:shinken,代码行数:10,代码来源:datamanager.py


示例10: get_dep_graph_struct

    def get_dep_graph_struct(self, elt, levels=3):
        t = elt.__class__.my_type
        # We set the values for webui/plugins/depgraph/htdocs/js/eltdeps.js
        # so a node with important data for rendering
        # type = custom, business_impact and img_src.
        d = {'id' : elt.get_dbg_name(), 'name' : elt.get_dbg_name(),
             'data' : {'$type' : 'custom',
                       'business_impact' : elt.business_impact,
                       'img_src' : self.get_icon_state(elt),
                       },
             'adjacencies' : []
             }

        # Set the right info panel
        d['data']['infos'] = r'''%s <h2 class="%s"><img style="width : 64px; height:64px" src="%s"/> %s: %s</h2>
		       <p>since %s</p>
		       <div style="float:right;"> <a href="%s">%s</a></div>'''  % (
            '<img src="/static/images/star.png" alt="star">' * (elt.business_impact - 2),
            elt.state.lower(), self.get_icon_state(elt), elt.state, elt.get_full_name(),
            self.print_duration(elt.last_state_change, just_duration=True, x_elts=2),
            self.get_link_dest(elt), self.get_button('Go to details', img='/static/images/search.png'))
                       

        d['data']['elt_type'] = elt.__class__.my_type
        d['data']['is_problem'] = elt.is_problem
        d['data']['state_id'] = elt.state_id

        safe_print("ELT:%s is %s" % (elt.get_full_name(), elt.state))
        if elt.state in ['OK', 'UP', 'PENDING']:
            d['data']['circle'] = 'none'
        elif elt.state in ['DOWN', 'CRITICAL']:
            d['data']['circle'] = 'red'
        elif elt.state in ['WARNING', 'UNREACHABLE']:
            d['data']['circle'] = 'orange'
        else:
            d['data']['circle'] = 'none'
     

        # Now put in adj our parents
        for p in elt.parent_dependencies:
            pd = {'nodeTo' : p.get_dbg_name(),
                  'data' : {"$type":"line", "$direction": [elt.get_dbg_name(), p.get_dbg_name()]}}

            # Naive way of looking at impact
            if elt.state_id != 0 and p.state_id != 0:
                pd['data']["$color"] = 'Tomato'
            # If OK, show host->service as a green link
            elif elt.__class__.my_type != p.__class__.my_type:
                 pd['data']["$color"] = 'PaleGreen'
            d['adjacencies'].append(pd)

        # The sons case is now useful, it will be done by our sons
        # that will link us
        return d
开发者ID:mleinart,项目名称:shinken,代码行数:54,代码来源:helper.py


示例11: run_external_commands

 def run_external_commands(self, commands):
     if self.con is None:
         self.create_connection()
     if not self.alive:
         return None
     safe_print("Send %d commands", len(commands))
     try:
         self.con.run_external_commands(commands)
     except Pyro.errors.URIError , exp:
         self.con = None
         return False
开发者ID:bs-github,项目名称:shinken,代码行数:11,代码来源:schedulerlink.py


示例12: unacknowledge_problem

 def unacknowledge_problem(self):
     if self.problem_has_been_acknowledged:
         safe_print("Deleting acknowledged of", self.get_dbg_name())
         self.problem_has_been_acknowledged = False
         # Should not be deleted, a None is Good
         self.acknowledgement = None
         # del self.acknowledgement
         # find comments of non-persistent ack-comments and delete them too
         for c in self.comments:
             if c.entry_type == 4 and not c.persistent:
                 self.del_comment(c.id)
         self.broks.append(self.get_update_status_brok())
开发者ID:pydubreucq,项目名称:shinken,代码行数:12,代码来源:item.py


示例13: create_json_dep_graph

 def create_json_dep_graph(self, elt, levels=3):
     t0 = time.time()
     # First we need ALL elements
     all_elts = self.get_all_linked_elts(elt, levels=levels)
     print "We got all our elements"
     dicts = []
     for i in all_elts:
         safe_print("Elt", i.get_dbg_name())
         d = self.get_dep_graph_struct(i)
         dicts.append(d)
     j = json.dumps(dicts)
     safe_print("Create json", j)
     print "create_json_dep_graph::Json creation time", time.time() - t0
     return j
开发者ID:bclermont,项目名称:shinken,代码行数:14,代码来源:helper.py


示例14: is_correct

    def is_correct(self):
        res = True

        if self.unknown_members != []:
            for m in self.unknown_members:
                safe_print("Error : the", self.__class__.my_type, self.get_name(), "got a unknown member" , m)
            res = False

        if self.configuration_errors != []:
            for err in self.configuration_errors:
                print err
            res = False
            
        return res
开发者ID:mleinart,项目名称:shinken,代码行数:14,代码来源:itemgroup.py


示例15: manage_unknown_command

def manage_unknown_command(elt):
    safe_print('Get an unmanaged command perfdata of', elt.get_full_name())
    p = PerfDatas(elt.perf_data)
    if len(p) == 0:
        return None

    m = None
    # Got some override name we know to be ok for printing
    if 'time' in p:
        m = p['time']
    else:
        for v in p:
            #print "Look for", v
            if v.name is not None and v.value is not None:
                m = v
                break

    prop = m.name
    safe_print("Got a property", prop, "and a value", m)
    v = m.value
    if not v:
        print "No value, I bailout"
        return None

    # Now look if min/max are available or not
    pct = 0
    if m.min and m.max and (m.max - m.min != 0):
        pct = 100 * (v / (m.max - m.min))
    else:  # ok, we will really guess this time...
        # Percent of ok should be time/10s
        pct = 100 * (v / 10)

    # go to int
    pct = int(pct)
    # But at least 1%
    pct = max(1, pct)
    # And max to 100%
    pct = min(pct, 100)
    lnk = '#'

    color = get_linear_color(elt, prop)
    s_color = 'RGB(%d,%d,%d)' % color
    metrics = [(s_color, pct), ('white', 100-pct)]
    uom = '' or m.uom
    title = '%s%s' % (v, uom)
    #print "HTTP: return", {'lnk': lnk, 'metrics': metrics, 'title': title}
    return {'lnk': lnk, 'metrics': metrics, 'title': title}
开发者ID:A3Sec,项目名称:mod-webui,代码行数:47,代码来源:perfdata_guess.py


示例16: get_all_linked_elts

    def get_all_linked_elts(self, elt, levels=3):
        if levels == 0:
            return set()

        my = set()
        for i in elt.child_dependencies:
            my.add(i)
            child_elts = self.get_all_linked_elts(i, levels=levels - 1)
            for c in child_elts:
                my.add(c)
        for i in elt.parent_dependencies:
            my.add(i)
            par_elts = self.get_all_linked_elts(i, levels=levels - 1)
            for c in par_elts:
                my.add(c)

        safe_print("get_all_linked_elts::Give elements", my)
        return my
开发者ID:bclermont,项目名称:shinken,代码行数:18,代码来源:helper.py


示例17: get_perfometer_table_values

def get_perfometer_table_values(elt):
    # first try to get the command name called
    cmd = elt.check_command.call.split('!')[0]
    safe_print("Looking for perfometer value for command", cmd)

    tab = {'check_http': manage_check_http_command,
           'check_ping': manage_check_ping_command,
           'check_tcp': manage_check_tcp_command,
           'check_ftp': manage_check_tcp_command,
        }

    f = tab.get(cmd, None)
    if f:
        return f(elt)

    try:
        r = manage_unknown_command(elt)
    except:
        return None
    return r
开发者ID:A3Sec,项目名称:mod-webui,代码行数:20,代码来源:perfdata_guess.py


示例18: manage_initial_contact_status_brok

    def manage_initial_contact_status_brok(self, b):
        """overwrite it, because the original method deletes some values"""
        data = b.data
        cname = data['contact_name']
        safe_print("Contact with data", data)
        c = self.contacts.find_by_name(cname)
        if c:
            self.update_element(c, data)
        else:
            safe_print("Creating Contact:", cname)
            c = Contact({})
            self.update_element(c, data)
            self.contacts[c.id] = c

        # Now manage notification ways too
        # Same than for contacts. We create or
        # update
        nws = c.notificationways
        safe_print("Got notif ways", nws)
        new_notifways = []
        for cnw in nws:
            nwname = cnw.notificationway_name
            nw = self.notificationways.find_by_name(nwname)
            if not nw:
                safe_print("Creating notif way", nwname)
                nw = NotificationWay([])
                self.notificationways[nw.id] = nw
            # Now update it
            for prop in NotificationWay.properties:
                if hasattr(cnw, prop):
                    setattr(nw, prop, getattr(cnw, prop))
            new_notifways.append(nw)

            # Linking the notification way
            # With commands
            self.linkify_commands(nw, 'host_notification_commands')
            self.linkify_commands(nw, 'service_notification_commands')


            # Now link timeperiods
            self.linkify_a_timeperiod(nw, 'host_notification_period')
            self.linkify_a_timeperiod(nw, 'service_notification_period')

        c.notificationways = new_notifways

        # Ok, declare this contact now :)
        # And notif ways too
        self.contacts.create_reversed_list()
        self.notificationways.create_reversed_list()
开发者ID:lausser,项目名称:shinken,代码行数:49,代码来源:livestatus_regenerator.py


示例19: show_impacts

def show_impacts():
    # First we look for the user sid
    # so we bail out if it's a false one
    user = app.get_user_auth()

    if not user:
        redirect("/user/login")
#        return {'app' : app, 'impacts' : {}, 'valid_user' : False, 'user' : user}

    
    all_imp_impacts = app.datamgr.get_important_elements()
    all_imp_impacts.sort(hst_srv_sort)

    impacts = {}

    imp_id = 0
    for imp in all_imp_impacts:
        safe_print("FIND A BAD SERVICE IN IMPACTS", imp.get_dbg_name())
        imp_id += 1
        impacts[imp_id] = imp

    return {'app' : app, 'impacts' : impacts, 'valid_user' : True, 'user' : user}
开发者ID:mleinart,项目名称:shinken,代码行数:22,代码来源:impacts.py


示例20: manage_check_tcp_command

def manage_check_tcp_command(elt):
    safe_print('Get check_tcp perfdata of', elt.get_full_name())
    p = PerfDatas(elt.perf_data)
    if not 'time' in p:
        print "No time in p"
        return None

    m = p['time']
    v = m.value

    if not v or not m.max:
        print "No value, I bailout"
        return None

    # Percent of ok should be the log of time versus m.max / 2
    pct = get_logarithmic(v, m.max/2)

    # Now get the color
    # OK : #6f2 (102,255,34) green
    # Warning : #f60 (255,102,0) orange
    # Crit : #ff0033 (255,0,51)
    base_color = {0 : (102,255,34), 1 : (255,102,0), 2 : (255,0,51)}
    state_id = get_stateid(elt)
    color = base_color.get(state_id, (179,196,255))
    s_color = 'RGB(%d,%d,%d)' % color    

    #pct = 100 * (v / m.max)
    # go to int
    #pct = int(pct)
    # But at least 1%
    #pct = max(1, pct)
    #And max to 100%
    #pct = min(pct, 100)
    lnk = '#'
    metrics = [(s_color, pct), ('white', 100-pct)]
    title = '%ss' % v
    print "HTTP: return", {'lnk' : lnk, 'metrics' : metrics, 'title' : title}
    return {'lnk' : lnk, 'metrics' : metrics, 'title' : title}
开发者ID:bs-github,项目名称:shinken,代码行数:38,代码来源:perfdata_guess.py



注:本文中的shinken.util.safe_print函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.strip_and_uniq函数代码示例发布时间:2022-05-27
下一篇:
Python util.get_start_of_day函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap