本文整理汇总了Python中shinken.util.safe_print函数的典型用法代码示例。如果您正苦于以下问题:Python safe_print函数的具体用法?Python safe_print怎么用?Python safe_print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_print函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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}
示例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
示例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
示例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}
示例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}
示例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}
示例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()
示例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 = []
示例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
示例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
示例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
示例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())
示例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
示例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
示例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}