示例#1
0
        private void bwMonitor_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;

            if (worker == null)
            {
                throw new Exception("Aconteceu algo com o BackgroundWorker");
            }

            var list = lstMonitoringLog;
            var code = new Action <MonitorEvent>((v) => { list.Items.Add(v); list.TopIndex = list.Items.Count - 1; });

            // TODO: Corrigir o problema do Enumerator quando remove um host da collection original
            var hostsCopy = new SNMPHost[Hosts.Count];

            Hosts.CopyTo(hostsCopy, 0);

            // Executa o Monitor passando todos os Hosts
            foreach (var evt in SNMPMonitor.Instance.Exec(hostsCopy))
            {
                if (list.InvokeRequired)
                {
                    list.Invoke(code, evt);
                }
                else
                {
                    code.Invoke(evt);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Escaneia uma lista de IP's em busca de respostas SNMP.
        /// Caso obtenha resposta cria um SNMPHost representando este Host.
        /// </summary>
        /// <returns>Hosts com SNMP</returns>
        private IList <SNMPHost> SNMPGetSysName(IList <IPAddress> ipList)
        {
            List <SNMPHost> foundList = new List <SNMPHost>();

            using (var q = new SuperQueue <IPAddress>(
                       ThreadCount / 2, // Reduz as threads para não sobrecarregar a rede
                       delegate(IPAddress ip)
            {
                var host = new SNMPHost()
                {
                    Community = Comunidade, IP = ip, Port = Porta
                };
                var request = new SNMPRequest(host, SNMP_SYSNAME)
                {
                    TimeOut = PingTimeout,
                    Retries = 4,
                    LogRequests = false                     // Não loga para economizar recursos
                };

                try
                {
                    request.Send();
                    if (request.ResponseValue != null)
                    {
                        Debug.WriteLine(ip);

                        // Define o nome retornado pelo SNMP
                        host.Name = request.ResponseValue.ToString();

                        // Adiciona na lista
                        lock (foundList)
                            foundList.Add(host);
                    }
                }
                catch { }     // Ignora erros
            }))
            {
                Debug.WriteLine("Verificando protocolo SNMP");
                foreach (var ip in ipList)
                {
                    q.EnqueueTask(ip);
                }
            }
            return(foundList);
        }
示例#3
0
        /// <summary>
        /// Verifica se o Host está ativo (respondendo a requisições)
        /// </summary>
        private bool IsAlive(SNMPHost host)
        {
            var mibObj = new MibObject()
            {
                OID = "1.3.6.1.2.1.1.3"
            };
            var req = new SNMPRequest(host, mibObj)
            {
                LogRequests = false
            };

            try
            {
                req.Send();
                if (req.ResponseValue != null)
                {
                    return(true);
                }
            }
            catch { }
            return(false);
        }
示例#4
0
        private void bwMonitor_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            if (worker == null)
                throw new Exception("Aconteceu algo com o BackgroundWorker");

            var list = lstMonitoringLog;
            var code = new Action<MonitorEvent>((v) => { list.Items.Add(v); list.TopIndex = list.Items.Count - 1; });

            // TODO: Corrigir o problema do Enumerator quando remove um host da collection original
            var hostsCopy = new SNMPHost[Hosts.Count];
            Hosts.CopyTo(hostsCopy, 0);

            // Executa o Monitor passando todos os Hosts
            foreach (var evt in SNMPMonitor.Instance.Exec(hostsCopy))
            {
                if (list.InvokeRequired)
                    list.Invoke(code, evt);
                else
                    code.Invoke(evt);
            }
        }
示例#5
0
 public SNMPRequest(SNMPHost host, MibObject obj)
 {
     Host        = host;
     Object      = obj;
     LogRequests = true;
 }
示例#6
0
 public MonitorEvent(SNMPHost h, MonitorKind t)
 {
     Host = h;
     Tipo = t;
     Timestamp = DateTime.Now;
 }
示例#7
0
 public SNMPRequest(SNMPHost host, MibObject obj)
 {
     Host = host;
     Object = obj;
     LogRequests = true;
 }
 public SNMPCommunications(SNMPHost host, MibObject obj)
     : base(host, obj)
 {
 }
 public SNMPCommunications(SNMPHost host, MibObject obj)
     : base(host, obj)
 {
 }
示例#10
0
 public MonitorEvent(SNMPHost h, MonitorKind t)
 {
     Host      = h;
     Tipo      = t;
     Timestamp = DateTime.Now;
 }
示例#11
0
 /// <summary>
 /// Verifica se o Host está ativo (respondendo a requisições)
 /// </summary>
 private bool IsAlive(SNMPHost host)
 {
     var mibObj = new MibObject() { OID = "1.3.6.1.2.1.1.3" };
     var req = new SNMPRequest(host, mibObj) { LogRequests = false };
     try
     {
         req.Send();
         if (req.ResponseValue != null)
             return true;
     }
     catch { }
     return false;
 }
        /// <summary>
        /// Escaneia uma lista de IP's em busca de respostas SNMP.
        /// Caso obtenha resposta cria um SNMPHost representando este Host.
        /// </summary>
        /// <returns>Hosts com SNMP</returns>
        private IList<SNMPHost> SNMPGetSysName(IList<IPAddress> ipList)
        {
            List<SNMPHost> foundList = new List<SNMPHost>();

            using (var q = new SuperQueue<IPAddress>(
                ThreadCount / 2, // Reduz as threads para não sobrecarregar a rede
                delegate(IPAddress ip)
                {
                    var host = new SNMPHost() { Community = Comunidade, IP = ip, Port = Porta };
                    var request = new SNMPRequest(host, SNMP_SYSNAME)
                                    {
                                        TimeOut = PingTimeout,
                                        Retries = 4,
                                        LogRequests = false // Não loga para economizar recursos
                                    };

                    try
                    {
                        request.Send();
                        if (request.ResponseValue != null)
                        {
                            Debug.WriteLine(ip);

                            // Define o nome retornado pelo SNMP
                            host.Name = request.ResponseValue.ToString();

                            // Adiciona na lista
                            lock (foundList)
                                foundList.Add(host);
                        }
                    }
                    catch { } // Ignora erros
                }))
            {
                Debug.WriteLine("Verificando protocolo SNMP");
                foreach (var ip in ipList)
                    q.EnqueueTask(ip);
            }
            return foundList;
        }