예제 #1
0
        static void Main(string[] args)
        {
            //gov.sandia.sld.common.logging.EventLog.GlobalSource = "COMMONCLI";

            string        ip_address                    = string.Empty;
            string        username                      = string.Empty;
            string        password                      = string.Empty;
            string        connection_string             = string.Empty;
            EDatabaseType db_type                       = EDatabaseType.Unknown;
            int           repeat_count                  = 1;
            int           pause_seconds_between_repeats = 1;
            List <string> to_collect                    = new List <string>();
            bool          show_usage                    = false;

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "/u":
                    if (i + 1 < args.Length)
                    {
                        username = args[++i].Trim();
                    }
                    break;

                case "/p":
                    if (i + 1 < args.Length)
                    {
                        password = args[++i].Trim();
                    }
                    break;

                case "/i":
                    if (i + 1 < args.Length)
                    {
                        ip_address = args[++i].Trim();
                    }
                    break;

                case "/d":
                {
                    switch (args[++i].Trim().ToLower())
                    {
                    case "sqlserver":
                        db_type = EDatabaseType.SqlServer;
                        break;

                    case "oracle":
                        db_type = EDatabaseType.Oracle;
                        break;

                    case "postgres":
                        db_type = EDatabaseType.Postgres;
                        break;
                    }
                    break;
                }

                case "/c":
                    connection_string = args[++i];
                    break;

                case "/r":
                    int.TryParse(args[++i], out repeat_count);
                    break;

                case "/s":
                    int.TryParse(args[++i], out pause_seconds_between_repeats);
                    break;

                case "/?":
                    show_usage = true;
                    break;

                default:
                    to_collect.Add(args[i]);
                    break;
                }
            }

            RequestBus.Instance.Subscribe(new PingResponder(ip_address));
            //RequestBus.Instance.Subscribe(new SystemErrorsInfoResponder());

            Remote r           = null;
            string device_name = "local";

            if (string.IsNullOrEmpty(ip_address) == false &&
                string.IsNullOrEmpty(username) == false &&
                string.IsNullOrEmpty(password) == false)
            {
                r           = new Remote(ip_address, username, password);
                device_name = ip_address;
            }

            CollectorID c_id = new CollectorID(-1, device_name);
            Dictionary <string, DataCollector> collector_map = new Dictionary <string, DataCollector>();

            collector_map["disk"]         = new DiskUsageCollector(c_id, r);
            collector_map["disknames"]    = new DiskNameCollector(c_id, r);
            collector_map["smart"]        = new SMARTCollector(c_id, r);
            collector_map["memory"]       = new MemoryUsageCollector(c_id, r);
            collector_map["cpu"]          = new CPUUsageCollector(c_id, r);
            collector_map["nic"]          = new NICUsageCollector(c_id, r);
            collector_map["uptime"]       = new UptimeCollector(c_id, r);
            collector_map["boot"]         = new LastBootTimeCollector(c_id, r);
            collector_map["processes"]    = new ProcessesCollector(c_id, r);
            collector_map["applications"] = new ApplicationsCollector(c_id, r);
            collector_map["services"]     = new ServicesCollector(c_id, r);
            collector_map["ups"]          = new UPSCollector(c_id, r);
            collector_map["database"]     = new DatabaseSizeCollector(c_id, false, new DatabaseCollectorFactory())
            {
                DBType           = db_type,
                ConnectionString = connection_string
            };
            //collector_map["antivirus"] = new AntiVirusCollector(c_id, r);
            //collector_map["firewall"] = new FirewallCollector(c_id, r);
            collector_map["ping"]              = new PingCollector(c_id);
            collector_map["systemerrors"]      = new SystemErrorLogCollector(c_id, r);
            collector_map["applicationerrors"] = new ApplicationErrorLogCollector(c_id, r);

            if (show_usage)
            {
                ShowUsage(collector_map.Keys);
                return;
            }

            if (to_collect.Count == 0)
            {
                foreach (string collector in collector_map.Keys)
                {
                    to_collect.Add(collector);
                }
            }

            List <DataCollector> c = new List <DataCollector>();

            foreach (string collector in to_collect)
            {
                if (collector_map.TryGetValue(collector, out DataCollector c2))
                {
                    c2.AttachDataAcquiredHandler(OnDataAcquired);
                    c.Add(c2);
                }
                else
                {
                    WriteLine($"Unknown collector: {collector}");
                }
            }

            if (c.Count == 0)
            {
                ShowUsage(collector_map.Keys);
            }
            else
            {
                GlobalIsRunning.IsRunning = true;

                for (int i = 0; i < repeat_count; ++i)
                {
                    foreach (DataCollector collector in c)
                    {
                        if (collector is PingCollector)
                        {
                            WriteLine($"Pinging {ip_address}");
                        }
                        else
                        {
                            WriteLine($"Collecting {collector.Context.Name}:");
                        }

                        watch = Stopwatch.StartNew();
                        collector.Acquire();
                    }

                    if ((i + 1) < repeat_count && pause_seconds_between_repeats > 0)
                    {
                        Thread.Sleep(pause_seconds_between_repeats * 1000);
                    }
                }
            }
        }
예제 #2
0
        public static Data Create(DataCollectorContext context, string value)
        {
            Data d = null;

            switch (context.Type)
            {
            case ECollectorType.Memory:
                d = MemoryUsageCollector.Create(context, value);
                break;

            case ECollectorType.Disk:
                d = DiskUsageCollector.Create(context, value);
                break;

            case ECollectorType.CPUUsage:
                d = CPUUsageCollector.Create(context, value);
                break;

            case ECollectorType.NICUsage:
                d = NICUsageCollector.Create(context, value);
                break;

            case ECollectorType.Uptime:
                d = UptimeCollector.Create(context, value);
                break;

            case ECollectorType.LastBootTime:
                d = LastBootTimeCollector.Create(context, value);
                break;

            case ECollectorType.Processes:
                d = ProcessesCollector.Create(context, value);
                break;

            case ECollectorType.Ping:
                d = PingCollector.Create(context, value);
                break;

            case ECollectorType.InstalledApplications:
                d = ApplicationsCollector.Create(context, value);
                break;

            case ECollectorType.Services:
                d = ServicesCollector.Create(context, value);
                break;

            case ECollectorType.SystemErrors:
                d = EventLogCollector.Create(context, value);
                break;

            case ECollectorType.ApplicationErrors:
                d = EventLogCollector.Create(context, value);
                break;

            case ECollectorType.DatabaseSize:
                d = DatabaseSizeCollector.Create(context, value);
                break;

            case ECollectorType.UPS:
                d = UPSCollector.Create(context, value);
                break;

            case ECollectorType.DiskSpeed:
                d = DiskSpeedCollector.Create(context, value);
                break;

            case ECollectorType.Configuration:
                break;

            case ECollectorType.SMART:
                break;

            //case CollectorType.AntiVirus:
            //case CollectorType.Firewall:
            case ECollectorType.Unknown:
            default:
                break;
            }

            return(d);
        }