Exemple #1
0
        private static void ProcQueue(Object oIndex)
        {
            Int32 index = (Int32)oIndex;

            LoadTestDatabase db = new LoadTestDatabase(env.ConnectionString);


            while (true)
            {
                try
                {
                    TrapQueueItem queueItem = null;

                    while ((queueItem = _queue.nextItem) != null)
                    {
                        SNMPTrap trap = new SNMPTrap(queueItem.receivedDate, queueItem.receivedEP, queueItem.packet);
                        db.insertMessages(env.TestName, "8. SNMP Trap from " + trap.receivedEP.Address.ToString(), trap.ToString());

#if DEBUG
                        Console.WriteLine(trap.ToString());
#else
                        Console.Write(".");
#endif
                    }
                }
                catch { }

                Thread.Sleep(300);
            }
        }
Exemple #2
0
        static void connectionStarter_OnBulkEvent(DataTable data, string tableName)
        {
            Console.Write(",");

            for (Int32 t = 1; t <= 3; t++)
            {
                LoadTestDatabase mydb = null;
                try
                {
                    mydb = new LoadTestDatabase(env.ConnectionString);

                    mydb.BulkCopy(data, tableName);

                    data.Dispose();

                    break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ZabbixMonitor.OnBulkEvent: Falha ao processar os dados " + ex.Message);
                }
                finally
                {
                    if (mydb != null)
                    {
                        mydb.Dispose();
                    }
                    mydb = null;
                }
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (args.Length == 0)
            {
                Console.WriteLine("Lista de argumentos está vazia");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            FileInfo configFile = null;

            try
            {
                configFile = new FileInfo(args[0]);
            }
            catch
            {
                Console.WriteLine("O argumento 0 não é um caminho de arquivo válido");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            if ((configFile == null) || (!configFile.Exists))
            {
                Console.WriteLine("Arquivo de configuração inexistente");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            env = new TestEnvironment();
            try
            {
                env.LoadConfig(configFile.FullName);

                try
                {
                    //configFile.Delete();
                }
                catch { }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Falha ao carregar o arquivo de configuração");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            //Testa conexão com banco de dados
            try
            {
                LoadTestDatabase mydb = new LoadTestDatabase(env.ConnectionString);

                mydb.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Falha ao conectar ao banco de dados: " + ex.Message);
                System.Threading.Thread.Sleep(3000);
                return;
            }

            _queue = new TrapQueue();
            Thread procQueue = new Thread(new ParameterizedThreadStart(ProcQueue));

            procQueue.Start(0);

            int        port = 162;
            UdpClient  listener;
            IPEndPoint groupEP;

            byte[] packet = new byte[1024];

            Console.WriteLine("Initializing SNMP Listener on Port:" + port + "...");

            // try
            // {
            listener = new UdpClient(port);
            groupEP  = new IPEndPoint(IPAddress.Any, port);

            while (true)
            {
                packet = listener.Receive(ref groupEP);
                if (packet.Length > 10)
                {
                    try
                    {
                        _queue.Add(DateTime.Now, groupEP, packet);
                        //SNMPTrap trap = new SNMPTrap(DateTime.Now, groupEP, packet);
                    }
                    catch { }
                }
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (args.Length == 0)
            {
                Console.WriteLine("Lista de argumentos está vazia");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            FileInfo configFile = null;

            try
            {
                configFile = new FileInfo(args[0]);
            }
            catch
            {
                Console.WriteLine("O argumento 0 não é um caminho de arquivo válido");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            if ((configFile == null) || (!configFile.Exists))
            {
                Console.WriteLine("Arquivo de configuração inexistente");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            env = new TestEnvironment();
            try
            {
                env.LoadConfig(configFile.FullName);

                try
                {
                    //configFile.Delete();
                }
                catch { }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Falha ao carregar o arquivo de configuração");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            //Testa conexão com banco de dados
            try
            {
                LoadTestDatabase mydb = new LoadTestDatabase(env.ConnectionString);

                mydb.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Falha ao conectar ao banco de dados: " + ex.Message);
                System.Threading.Thread.Sleep(3000);
                return;
            }


            Console.WriteLine("Starting zabbix monitors...");

            MonitorStarter connectionStarter = new MonitorStarter();

            connectionStarter.SetStartupConfig(env, null);

            connectionStarter.OnDebugEvent += new MonitorStarter.DebugEvent(connectionStarter_OnDebugEvent);
            connectionStarter.OnBulkEvent  += new MonitorStarter.BulkEvent(connectionStarter_OnBulkEvent);

            connectionStarter.StartMonitor();

            /*
             * if (env.ZabbixMonitors != null)
             * {
             *  foreach (ZabbixConfig c in env.ZabbixMonitors)
             *  {
             *      Thread mon = new Thread(new ParameterizedThreadStart(startThread));
             *      mon.Start(c);
             *
             *  }
             * }*/

            /*
             * Zabbix zbx = new Zabbix("172.24.0.1");
             * //String tst = zbx.GetItem("net.if.discovery");
             * String tst = zbx.GetItem("net.if.in[eth0]");
             * System.Threading.Thread.Sleep(1000);
             * String tst2 = zbx.GetItem("net.if.in[eth0]");
             *
             * Console.WriteLine(Int64.Parse(tst2) - Int64.Parse(tst));
             *
             * Console.WriteLine(tst);*/

            while (true)
            {
                Console.ReadLine();
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (args.Length == 0)
            {
                Console.WriteLine("Lista de argumentos está vazia");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            FileInfo configFile = null;

            try
            {
                configFile = new FileInfo(args[0]);
            }
            catch
            {
                Console.WriteLine("O argumento 0 não é um caminho de arquivo válido");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            if ((configFile == null) || (!configFile.Exists))
            {
                Console.WriteLine("Arquivo de configuração inexistente");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            env = new TestEnvironment();
            try
            {
                env.LoadConfig(configFile.FullName);

                try
                {
                    //configFile.Delete();
                }
                catch { }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Falha ao carregar o arquivo de configuração");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            //Testa conexão com banco de dados
            try
            {
                LoadTestDatabase mydb = new LoadTestDatabase(env.ConnectionString);

                mydb.Dispose();
            }
            catch (Exception ex) {
                Console.WriteLine("Falha ao conectar ao banco de dados: " + ex.Message);
                System.Threading.Thread.Sleep(3000);
                return;
            }


            Console.WriteLine("Starting with " + env.VirtualUsers + " usuários virtuais...");


            ClientStarter connectionStarter = new ClientStarter();

            connectionStarter.SetStartupConfig(env, null);
            //connectionStarter.LogDir = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "logs\\" + env.TestName + "\\conn_logs"));
            connectionStarter.OnVUCountReceived += new ClientStarter.VUCountReceived(connectionStarter_OnVUCountReceived);
            connectionStarter.OnResultReceived  += new ClientStarter.ResultReceived(connectionStarter_OnResultReceived);
            connectionStarter.OnDebugEvent      += new ClientStarter.DebugEvent(connectionStarter_OnDebugEvent);
            connectionStarter.OnBulkEvent       += new ClientStarter.BulkEvent(connectionStarter_OnBulkEvent);

            connectionStarter.StartConnections();


            while (true)
            {
                Console.ReadLine();
            }
        }