예제 #1
0
파일: views.py 프로젝트: jsoyee/wisemonitor
 def post(self, host_ip):
     error = None
     use = self.get_argument("use", "").strip()
     interface_index = self.get_argument("interface_index", "").strip()
     in_warn = self.get_argument("in_warn", "").strip()
     out_warn = self.get_argument("out_warn", "").strip()
     in_crit = self.get_argument("in_crit", "").strip()
     out_crit = self.get_argument("out_crit", "").strip()
     
     snmp_supported, community = nagios.check_if_snmp_supported(host_ip)
     if not snmp_supported:
         error = "failed"
         logger.error("host %s does not support SNMP!" % host_ip)
         all_interface = self.get_all_interface(host_ip, community)
         return self.render("infrastracture/add_service_data_traffic.html",
                            error=error, host_ip=host_ip,
                            snmp_supported=False,
                            all_interface=all_interface)
         
     try:
         speed, status, name, index = snmp.get_int_status(host_ip, community,
                                                          interface_index=interface_index)
     except Exception, e:
         logger.exception(e)
         error = "failed"
         return self.render("infrastracture/add_service_data_traffic.html",
                            error=None, host_ip=host_ip)
예제 #2
0
    def post(self, host_ip):
        error = None
        use = self.get_argument("use", "").strip()
        interface_index = self.get_argument("interface_index", "").strip()
        in_warn = self.get_argument("in_warn", "").strip()
        out_warn = self.get_argument("out_warn", "").strip()
        in_crit = self.get_argument("in_crit", "").strip()
        out_crit = self.get_argument("out_crit", "").strip()

        snmp_supported, community = nagios.check_if_snmp_supported(host_ip)
        if not snmp_supported:
            error = "failed"
            logger.error("host %s does not support SNMP!" % host_ip)
            all_interface = self.get_all_interface(host_ip, community)
            return self.render("infrastracture/add_service_data_traffic.html",
                               error=error,
                               host_ip=host_ip,
                               snmp_supported=False,
                               all_interface=all_interface)

        try:
            speed, status, name, index = snmp.get_int_status(
                host_ip, community, interface_index=interface_index)
        except Exception, e:
            logger.exception(e)
            error = "failed"
            return self.render("infrastracture/add_service_data_traffic.html",
                               error=None,
                               host_ip=host_ip)
예제 #3
0
파일: views.py 프로젝트: jsoyee/wisemonitor
 def check_snmp_supported(self, host_ip):
     """
     检查nagios配置文件中,主机是否支持SNMP
     如果支持返回它的SNMP Community
     """
     snmp_supported, community = nagios.check_if_snmp_supported(host_ip)
     self.community = community
     return snmp_supported, community
예제 #4
0
 def check_snmp_supported(self, host_ip):
     """
     检查nagios配置文件中,主机是否支持SNMP
     如果支持返回它的SNMP Community
     """
     snmp_supported, community = nagios.check_if_snmp_supported(host_ip)
     self.community = community
     return snmp_supported, community
예제 #5
0
 def post(self, host_ip):
     """
     根据端口index,查询端口的速度和状态
     """
     snmp_supported, community = nagios.check_if_snmp_supported(host_ip)
     if snmp_supported:
         interface_index = self.get_argument("index", "").strip()
         interface_name = self.get_argument("name", "").strip()
         interface_name = interface_name.split(" ")[0]
         try:
             ret = snmp.get_int_status(host_ip,
                                       community,
                                       interface_index=int(interface_index))
             if ret != None:
                 interface_speed, interface_status, _, _ = ret
             else:
                 msg = {
                     "interface_name": interface_name,
                     "speed": 0,
                     "status": 2
                 }
                 self.write(json.dumps(msg))
                 return
         except Exception, e:
             logger.error("Get interface %s status failed!" %
                          interface_name)
             msg = {
                 "interface_name": interface_name,
                 "speed": 0,
                 "status": 2
             }
             self.write(json.dumps(msg))
         else:
             if interface_speed or interface_status:
                 msg = {
                     "interface_name": interface_name,
                     "speed": int(interface_speed),
                     "status": int(interface_status)
                 }
                 self.write(json.dumps(msg))
예제 #6
0
파일: views.py 프로젝트: jsoyee/wisemonitor
 def post(self, host_ip):
     """
     根据端口index,查询端口的速度和状态
     """
     snmp_supported, community = nagios.check_if_snmp_supported(host_ip)
     if snmp_supported:
         interface_index = self.get_argument("index", "").strip()
         interface_name = self.get_argument("name", "").strip()
         interface_name = interface_name.split(" ")[0]
         try:
             ret = snmp.get_int_status(host_ip, community,
                                                                     interface_index=int(interface_index))
             if ret != None:
                 interface_speed, interface_status, _, _ = ret
             else:
                 msg = {
                     "interface_name": interface_name,
                     "speed": 0,
                     "status": 2 
                 }
                 self.write(json.dumps(msg))
                 return
         except Exception, e:
             logger.error("Get interface %s status failed!" % interface_name)
             msg = {
                 "interface_name": interface_name,
                 "speed": 0,
                 "status": 2 
             }
             self.write(json.dumps(msg))
         else:
             if interface_speed or interface_status:
                 msg = {
                     "interface_name": interface_name,
                     "speed": int(interface_speed),
                     "status": int(interface_status)
                 }
                 self.write(json.dumps(msg))