コード例 #1
0
 def to_hint(self, srv_reply):
     cur_ns = Namespace(
         get_hints=True,
     )
     r_dict = supermicro_mod.generate_dict(srv_reply.xpath(".//ns:output/text()", smart_strings=False)[0].split("\n"))
     _hints = [
         monitoring_hint(
             key="overview",
             v_type="s",
             value_string="check",
             info="SMC Overview",
             is_active=True,
         )
     ]
     for m_key in sorted(r_dict):
         _struct = r_dict[m_key]
         for e_key in sorted([_key for _key in _struct.iterkeys() if type(_key) in [int]]):
             _hints.append(
                 monitoring_hint(
                     key="{}.{:d}".format(m_key, e_key),
                     v_type="s",
                     value_string="present",
                     info=u"{} {:d}".format(_struct["info"], e_key),
                     is_active=False,
                 )
             )
     return _hints
コード例 #2
0
ファイル: special_ovirt.py プロジェクト: bopopescu/icsw
 def to_hint(self, srv_reply):
     _hints = []
     VALID_STATES = {"up", "down"}
     if srv_reply is not None:
         # print srv_reply.pretty_print()
         info_dict = {
             "run_ids": [],
             "run_names": [],
         }
         doms = ovirt_mod.StorageDomain.deserialize(srv_reply)
         for sd in doms:
             _dom_id = sd.get("id")
             _dom_name = sd.findtext("name")
             info_dict["run_ids"].append(_dom_id)
             info_dict["run_names"].append(_dom_name)
             _hints.append(
                 monitoring_hint(
                     key="storage_domain_{}".format(_dom_id),
                     v_type="s",
                     info="ovirt StorageDomain {}".format(_dom_name),
                     value_string=_dom_name,
                     persistent=True,
                     is_active=False,
                 ))
         _hints.append(
             monitoring_hint(
                 key="overview",
                 v_type="B",
                 info="StorageDomain overview",
                 persistent=True,
                 value_blob=process_tools.compress_struct(info_dict),
                 is_active=True,
             ))
     return _hints
コード例 #3
0
ファイル: special_ovirt.py プロジェクト: bopopescu/icsw
 def to_hint(self, srv_reply):
     _hints = []
     if srv_reply is not None:
         # print srv_reply.pretty_print()
         info_dict = {
             "run_ids": [],
             "run_names": [],
         }
         hosts = ovirt_mod.Host.deserialize(srv_reply)
         for host in hosts:
             _host_id = host.get("id")
             _host_name = host.findtext("name")
             info_dict["run_ids"].append(_host_id)
             info_dict["run_names"].append(_host_name)
             _hints.append(
                 monitoring_hint(
                     key="host_{}".format(_host_id),
                     v_type="s",
                     info="ovirt Host {}".format(_host_name),
                     value_string=_host_name,
                     persistent=True,
                     is_active=False,
                 ))
         _hints.append(
             monitoring_hint(
                 key="overview",
                 v_type="B",
                 info="Host overview",
                 persistent=True,
                 value_blob=process_tools.compress_struct(info_dict),
                 is_active=True,
             ))
     return _hints
コード例 #4
0
ファイル: special_ovirt.py プロジェクト: walong365/icsw
 def feed_result(self, dc_action, srv_reply):
     _hints = []
     if srv_reply is not None:
         # print srv_reply.pretty_print()
         info_dict = {
             "run_ids": [],
             "run_names": [],
         }
         hosts = ovirt_mod.Host.deserialize(srv_reply)
         for host in hosts:
             _host_id = host.get("id")
             _host_name = host.findtext("name")
             info_dict["run_ids"].append(_host_id)
             info_dict["run_names"].append(_host_name)
             _hints.append(
                 monitoring_hint(
                     key="host_{}".format(_host_id),
                     v_type="s",
                     info="ovirt Host {}".format(_host_name),
                     value_string=_host_name,
                     persistent=True,
                     is_active=False,
                 ))
         _hints.append(
             monitoring_hint(
                 key="overview",
                 v_type="j",
                 info="Host overview",
                 persistent=True,
                 value_json=json.dumps(info_dict),
                 is_active=True,
             ))
         self.store_hints(_hints)
     yield None
コード例 #5
0
ファイル: special_ovirt.py プロジェクト: walong365/icsw
 def feed_result(self, dc_action, srv_reply):
     _hints = []
     if srv_reply is not None:
         # print srv_reply.pretty_print()
         info_dict = {
             "run_ids": [],
             "run_names": [],
         }
         doms = ovirt_mod.StorageDomain.deserialize(srv_reply)
         for sd in doms:
             _dom_id = sd.get("id")
             _dom_name = sd.findtext("name")
             info_dict["run_ids"].append(_dom_id)
             info_dict["run_names"].append(_dom_name)
             _hints.append(
                 monitoring_hint(
                     key="storage_domain_{}".format(_dom_id),
                     v_type="s",
                     info="ovirt StorageDomain {}".format(_dom_name),
                     value_string=_dom_name,
                     persistent=True,
                     is_active=False,
                 ))
         _hints.append(
             monitoring_hint(
                 key="overview",
                 v_type="j",
                 info="StorageDomain overview",
                 persistent=True,
                 value_json=json.dumps(info_dict),
                 is_active=True,
             ))
         self.store_hints(_hints)
     yield None
コード例 #6
0
ファイル: special_ovirt.py プロジェクト: walong365/icsw
 def feed_result(self, dc_action, srv_reply):
     _hints = []
     VALID_STATES = {"up", "down"}
     if srv_reply is not None:
         # print srv_reply.pretty_print()
         info_dict = {key: 0 for key in VALID_STATES}
         info_dict["run_ids"] = []
         info_dict["run_names"] = []
         # print("-" * 20)
         # print(srv_reply.pretty_print())
         # print("+" * 20)
         if "vms" in srv_reply:
             for vm in srv_reply.xpath(".//ns:vms")[0]:
                 _xml = etree.fromstring(
                     server_command.decompress(vm.text, json=True))
                 # print(etree.tostring(_xml, pretty_print=True))
                 # try state paths
                 _state = _xml.xpath(".//status/state/text()")
                 if not len(_state):
                     _state = _xml.xpath(".//status/text()")
                 _state = _state[0]
                 if _state in VALID_STATES:
                     info_dict[_state] += 1
                 if _state == "up":
                     _dom_id = _xml.get("id")
                     _dom_name = _xml.findtext("name")
                     info_dict["run_ids"].append(_dom_id)
                     info_dict["run_names"].append(_dom_name)
                     _hints.append(
                         monitoring_hint(
                             key="domain_{}".format(_dom_id),
                             v_type="s",
                             info="ovirt Domain {}".format(_dom_name),
                             value_string=_dom_name,
                             persistent=True,
                             is_active=False,
                         ))
         _hints.append(
             monitoring_hint(
                 key="overview",
                 v_type="j",
                 info="Domain overview",
                 persistent=True,
                 value_json=json.dumps(info_dict),
                 is_active=True,
             ))
         self.store_hints(_hints)
     yield None
コード例 #7
0
ファイル: special_eonstor.py プロジェクト: walong365/icsw
 def _get_env_check(self, info, key, idx):
     return monitoring_hint(
         key=key,
         v_type="i",
         value_int=idx,
         info=info,
     )
コード例 #8
0
ファイル: special_ipmi.py プロジェクト: walong365/icsw
 def feed_result(self, dc_action, srv_reply):
     _hints = []
     if srv_reply is not None:
         if "list:sensor_list" in srv_reply:
             for sensor in srv_reply["list:sensor_list"]:
                 lim_dict = {
                     l_key: sensor.attrib[key]
                     for l_key, key in [(
                         "lower_warn",
                         "limit_lw"), (
                             "lower_crit",
                             "limit_lc"), (
                                 "upper_warn",
                                 "limit_uw"), ("upper_crit", "limit_uc")]
                     if key in sensor.attrib
                 }
                 new_hint = monitoring_hint(
                     key=sensor.attrib["key"],
                     v_type="f",
                     info=sensor.attrib["info"],
                 )
                 new_hint.update_limits(0.0, lim_dict)
                 _hints.append(new_hint)
     self.store_hints(_hints)
     yield None
コード例 #9
0
 def _transform_to_hint(self, entry):
     key, check, info, _active = entry
     return monitoring_hint(
         key=key,
         v_type="s",
         value_string=check,
         info=info,
         persistent=True,
         is_active=_active,
     )
コード例 #10
0
ファイル: special_ovirt.py プロジェクト: bopopescu/icsw
 def to_hint(self, srv_reply):
     _hints = []
     VALID_STATES = {"up", "down"}
     if srv_reply is not None:
         # print srv_reply.pretty_print()
         info_dict = {key: 0 for key in VALID_STATES}
         info_dict["run_ids"] = []
         info_dict["run_names"] = []
         if "vms" in srv_reply:
             for vm in srv_reply.xpath(".//ns:vms")[0]:
                 _xml = etree.fromstring(
                     process_tools.decompress_struct(vm.text))
                 _state = _xml.xpath(".//status/state/text()")[0]
                 if _state in VALID_STATES:
                     info_dict[_state] += 1
                 if _state == "up":
                     _dom_id = _xml.get("id")
                     _dom_name = _xml.findtext("name")
                     info_dict["run_ids"].append(_dom_id)
                     info_dict["run_names"].append(_dom_name)
                     _hints.append(
                         monitoring_hint(
                             key="domain_{}".format(_dom_id),
                             v_type="s",
                             info="ovirt Domain {}".format(_dom_name),
                             value_string=_dom_name,
                             persistent=True,
                             is_active=False,
                         ))
         _hints.append(
             monitoring_hint(
                 key="overview",
                 v_type="B",
                 info="Domain overview",
                 persistent=True,
                 value_blob=process_tools.compress_struct(info_dict),
                 is_active=True,
             ))
     return _hints
コード例 #11
0
ファイル: special_libvirt.py プロジェクト: bopopescu/icsw
 def to_hint(self, srv_reply):
     _hints = []
     if srv_reply is not None:
         if "domain_overview" in srv_reply:
             domain_info = srv_reply["domain_overview"]
             if "running" in domain_info and "defined" in domain_info:
                 domain_info = domain_info["running"]
             for _d_idx, d_dict in domain_info.iteritems():
                 new_hint = monitoring_hint(
                     key=d_dict["name"],
                     v_type="s",
                     info="Domain {}".format(d_dict["name"]),
                     value_string="running",
                 )
                 _hints.append(new_hint)
     return _hints
コード例 #12
0
 def to_hint(self, srv_reply):
     r_dict = supermicro_mod.generate_dict(srv_reply.xpath(".//ns:output/text()", smart_strings=False)[0].split("\n"))
     _hints = []
     for m_key in sorted(r_dict):
         _struct = r_dict[m_key]
         for e_key in sorted([_key for _key in _struct.iterkeys() if type(_key) in [int]]):
             _hints.append(
                 monitoring_hint(
                     key="{}.{:d}".format(m_key, e_key),
                     v_type="s",
                     value_string="present",
                     info="{} {:d}".format(_struct["info"], e_key),
                 )
             )
     if len(_hints):
         self.remove_cache_entries()
     return _hints
コード例 #13
0
ファイル: special_openvpn.py プロジェクト: bopopescu/icsw
 def to_hint(self, srv_reply):
     _hints = []
     if "openvpn_instances" in srv_reply:
         ovpn_dict = srv_reply["openvpn_instances"]
         for inst_name in ovpn_dict:
             if ovpn_dict[inst_name]["type"] == "server":
                 for c_name in ovpn_dict[inst_name]["dict"]:
                     _hints.append(
                         monitoring_hint(
                             key="{}|{}".format(inst_name, c_name),
                             v_type="s",
                             value_string="used",
                             info="Client {} on instance {}".format(
                                 c_name, inst_name),
                             persistent=True,
                         ))
     return _hints
コード例 #14
0
 def feed_result(self, dc_action, srv_reply):
     _hints = []
     if "openvpn_instances" in srv_reply:
         ovpn_dict = srv_reply["openvpn_instances"]
         for inst_name in ovpn_dict:
             if ovpn_dict[inst_name]["type"] == "server":
                 for c_name in ovpn_dict[inst_name]["dict"]:
                     _hints.append(
                         monitoring_hint(
                             key="{}|{}".format(inst_name, c_name),
                             v_type="s",
                             value_string="used",
                             info="Client {} on instance {}".format(c_name, inst_name),
                             persistent=True,
                         )
                     )
     self.store_hints(_hints)
     yield None
コード例 #15
0
ファイル: special_libvirt.py プロジェクト: walong365/icsw
 def feed_result(self, dc_action, srv_reply):
     _hints = []
     # print(srv_reply.pretty_print())
     if srv_reply is not None:
         # print("domain_overview" in srv_reply)
         if "domain_overview" in srv_reply:
             domain_info = srv_reply["domain_overview"]
             # print("***", domain_info)
             if "running" in domain_info and "defined" in domain_info:
                 domain_info = domain_info["running"]
             for _d_idx, d_dict in domain_info.items():
                 new_hint = monitoring_hint(
                     key=d_dict["name"],
                     v_type="s",
                     info="Domain {}".format(d_dict["name"]),
                     value_string="running",
                 )
                 _hints.append(new_hint)
     self.store_hints(_hints)
     yield None
コード例 #16
0
ファイル: dynconfig.py プロジェクト: walong365/icsw
 def _create_hints_ipmi(self, cur_dev, mon_info):
     cur_hints = {
         (cur_h.m_type, cur_h.key): cur_h
         for cur_h in monitoring_hint.objects.filter(Q(device=cur_dev))
     }
     # import pprint
     # pprint.pprint(cur_hints)
     # print("**", cur_hints)
     _ocsp_prefix = self._get_ipmi_service_prefix(cur_dev)
     if not _ocsp_prefix:
         self.log(
             "cannot get prefix for IPMI service results for device {}".
             format(str(cur_dev)))
     ocsp_lines = []
     # pprint.pprint(cur_hints)
     n_updated, n_created, n_deleted = (0, 0, 0)
     updated, created = (False, False)
     _used_types, _present_keys = (set(), set())
     for _val in mon_info:
         _key = (_val.get("m_type"), _val.get("name"))
         _present_keys.add(_key)
         _used_types.add(_val.get("m_type"))
         updated, created = (False, False)
         if _key in cur_hints:
             cur_hint = cur_hints[_key]
             # update
             for _sfn, _dfn in [("info", "info"), ("v_type", "v_type")]:
                 if _val.get(_sfn) != getattr(cur_hint, _dfn):
                     setattr(cur_hint, _dfn, _val.get(_sfn))
                     updated = True
         else:
             cur_hint = monitoring_hint(
                 device=cur_dev,
                 m_type=_val.get("m_type"),
                 v_type=_val.get("v_type"),
                 key=_val.get("name"),
                 info=_val.get("info"),
             )
             created = True
         limit_dict = {
             "{}_{}".format({
                 "l": "lower",
                 "u": "upper"
             }[_key[0]], {
                 "w": "warn",
                 "c": "crit"
             }[_key[1]]): float(_val.attrib[_key])
             for _key in ["lc", "uc", "lw", "uw"] if _key in _val.attrib
         }
         if _val.get("v_type") == "f":
             _value = float(_val.get("value"))
         else:
             _value = int(_val.get("value"))
         if cur_hint.update_limits(_value, limit_dict):
             updated = True
         if created or updated:
             if created:
                 n_created += 1
             if updated:
                 n_updated += 1
             cur_hint.save()
         # create passive check result
         cur_hint.set_value(_value)
         ret_code, ret_str = self._check_status_ipmi(_value, cur_hint)
         ocsp_line = "[{}] PROCESS_SERVICE_CHECK_RESULT;{};{};{:d};{}".format(
             mon_info.get("time"),
             cur_dev.full_name,
             "{}{}".format(_ocsp_prefix, _val.get("info")),
             ret_code,
             ret_str,
         )
         ocsp_lines.append(ocsp_line)
     # experimental: delete all hints with correct m_type
     if len(mon_info) and _used_types:
         _del_keys = [
             key for key, value in cur_hints.items()
             if key not in _present_keys and key[0] in _used_types
             and not value.persistent
         ]
         if _del_keys:
             self.log(
                 "{} / {}: {} to delete".format(
                     str(cur_dev), ", ".join(sorted(list(_used_types))),
                     logging_tools.get_plural("key", len(_del_keys))),
                 logging_tools.LOG_LEVEL_WARN)
             for _key in _del_keys:
                 cur_hints[_key].delete()
     # pprint.pprint(ocsp_lines)
     if _ocsp_prefix:
         self.send_pool_message("ocsp_results", ocsp_lines)
     if updated or created:
         self.log("for {}: created {:d}, updated {:d}".format(
             str(cur_dev), n_created, n_updated))