Exemplo n.º 1
0
        //cpu监控
        public void threadCpu(bool is_first, int exec)
        {
            string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool   begin  = tool.execute_or_not("cpu_running", db_dir, cpumem, is_first, exec);

            if (begin == true)
            {
                monitor    cpu        = new monitor();
                float      cpuValue   = cpu.getCpuUsedPercent();
                int        perOfCpu   = int.Parse(cpuValue.ToString().Split('.').ElementAt(0));
                RamCpuInfo ramCpuInfo = new RamCpuInfo();
                ramCpuInfo.WarningDateTime = DateTime.Now;
                ramCpuInfo.WarningValue    = perOfCpu;
                int cpuwarnvalue = int.Parse(tool.readconfig("jb", "cpuwarnvalue"));
                if (perOfCpu >= cpuwarnvalue)
                {
                    string str5 = System.Windows.Forms.Application.StartupPath;
                    string a    = str5 + "\\db.accdb";
                    Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                    db.AccessDbClass2(a);
                    string sql11 = "insert into Status_Histroy (para_name,details,create_date) values ('cpu_running','" + perOfCpu + "','" + DateTime.Now + "')";
                    bool   ee    = db.ExecuteSQLNonquery(sql11);
                    ////textBox3.Text = ee.ToString();
                }
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Tool_Class.IO_tool tool = new Tool_Class.IO_tool();
            string time = textBox1.Text;
            string jb = textBox3.Text;
            string bj = textBox2.Text;

            /*int t = int.Parse(iplist.Rows.Count.ToString());
            textBox4.Text = t.ToString();
            string ip = "";
            for (int i = 0; i < t - 1; i++)
            {

                ip += iplist.Rows[i].Cells[0].Value.ToString() + "=" + iplist.Rows[i].Cells[1].Value.ToString() + "=" + iplist.Rows[i].Cells[2].Value.ToString() + "=" + iplist.Rows[i].Cells[3].Value.ToString() + ";\r\n";
                writeip("ip",ip);

            }*/
            monitor mm = new monitor();
            //mm.writeconfig("rff", "ppt", "4");
            tool.writeconfig("rf", "netrefresh", time);
            tool.writeconfig("jb", "netwarn", jb);
            tool.writeconfig("bj", "neterror", bj);
            MessageBox.Show("修改成功");
            //textBox4.Text = iplist.Rows[0].Cells[0].Value.ToString() + "=" + iplist.Rows[0].Cells[1].Value.ToString() + "=" + iplist.Rows[0].Cells[2].Value.ToString() + "=" + iplist.Rows[0].Cells[3].Value.ToString() + ";";
        }
Exemplo n.º 3
0
        public void threadWarnSyslog()
        {
            List<EventLogEntry> eventLogList = new List<EventLogEntry>();
            monitor mmm = new monitor();
            List<string> eventTypelist = new List<string>();
            eventTypelist.Add("system");
            eventTypelist.Add("Application");
            eventTypelist.Add("Security");
            foreach (string eventType1 in eventTypelist)
            {
                eventLogList = mmm.getWarnEventLog(eventType1);
                bool found = false;
                foreach (EventLogEntry newEventLog in eventLogList)
                {
                    ////textBox4.Text = newEventLog.Message;
                    foreach (EventLogEntry exsitEventLog in ExsitListOfWarnEventLog)
                    {
                        if (exsitEventLog.TimeGenerated == newEventLog.TimeGenerated
                            && exsitEventLog.Category == newEventLog.Category
                            && exsitEventLog.Message == newEventLog.Message
                            && exsitEventLog.InstanceId == newEventLog.InstanceId
                            && exsitEventLog.UserName == newEventLog.UserName
                            && exsitEventLog.MachineName == newEventLog.MachineName)   //日志相同的只发送一次
                        {
                            found = true;//找到相同的了
                        }

                    }
                    if (!found) //没找到,添加进去,
                    {
                        ExsitListOfWarnEventLog.Add(newEventLog); //填入已存在列表里
                        eventLogTypeList eventList = new eventLogTypeList();
                        eventList.eventLogEntry = newEventLog;
                        eventList.eventLogType = eventType1;
                        WarningListOfWarnEventLog.Add(eventList);//发送警报列表里
                    }

                }
                eventLogList.Clear(); //处理完毕,清空
            }

            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();
            StringBuilder sb3 = new StringBuilder();
            StringBuilder sb4 = new StringBuilder();
            StringBuilder sb5 = new StringBuilder();
            if (WarningListOfWarnEventLog.Count > 0)
            {
                eventlogWarnNum += WarningListOfWarnEventLog.Count;
                foreach (eventLogTypeList eventLogType in WarningListOfWarnEventLog)
                {

                    string error = eventLogType.eventLogType + "日志出现警告!";
                    string message = eventLogType.eventLogEntry.Message;
                    eventlogWarnMessage += eventLogType.eventLogEntry.Message +"\n\r";
                    string sb = eventLogType.eventLogType + message + eventLogType.eventLogEntry.TimeGenerated;
                    string str5 = System.Windows.Forms.Application.StartupPath;
                    string a = str5 + "\\db.accdb";
                    Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                    db.AccessDbClass2(a);
                    string egg = "W";
                    string sql11 = "insert into Status_Histroy (para_name,details,flag,create_date,para_value) values ('syslog_warn','" + error + "%','" + egg + "','" + eventLogType.eventLogEntry.TimeGenerated + "','" + message + "')";
                    bool ee = db.ExecuteSQLNonquery(sql11);
                }
                WarningListOfWarnEventLog.Clear();
            }
        }
Exemplo n.º 4
0
        //内存监控
        public void threadMem(bool is_first, int exec)
        {
            string memvalue = "内存正常;\n\r";
            string memsign = "N";
            string cpuvalue = "CPU正常;\n\r";
            string cpusign = "N";
            string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool begin = tool.execute_or_not("cpu_running", db_dir, cpumem, is_first, exec);
            if (begin == true)
            {
                monitor mem = new monitor();
                uint memValue = mem.getRamUsePercent();
                int perOfRam = int.Parse(memValue.ToString().Split('.').ElementAt(0));
                int memerrorvalue = int.Parse(tool.readconfig("bj", "memerrorvalue"));
                int memerrortime = int.Parse(tool.readconfig("bj", "memerrortime"));
                int memwarnvalue = int.Parse(tool.readconfig("jb", "memwarnvalue"));
                int memwarntime = int.Parse(tool.readconfig("jb", "memwarntime"));
                if (perOfRam >= memwarnvalue)
                {
                    RamCpuInfo ramCpuInfo = new RamCpuInfo();
                    ramCpuInfo.WarningDateTime = DateTime.Now;
                    ramCpuInfo.WarningValue = perOfRam;
                    WarningListOfMem.Add(ramCpuInfo);
                    string str5 = System.Windows.Forms.Application.StartupPath;
                    string a = str5 + "\\db.accdb";
                    Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                    db.AccessDbClass2(a);
                    string sql11 = "insert into Status_Histroy (para_name,details,create_date) values ('memory_running','" + perOfRam + "','" + DateTime.Now + "')";
                    bool ee = db.ExecuteSQLNonquery(sql11);
                }
                    ////textBox3.Text = ee.ToString();
                    string sql5 = "select details from Status_Histroy where para_name = 'memory_running' and sign is null";
                    DataTable memerrorcount = tool.DbToDatatable(sql5);
                    int num = 0;
                    int errornum = 0;
                    for (int i = 0; i < memerrorcount.Rows.Count; i++)
                    {
                        int numm = int.Parse(memerrorcount.Rows[i][0].ToString());
                        if (numm > memwarnvalue)
                        {
                            num++;//达到警告值的次数
                        }
                        if (numm > memerrorvalue)
                        {
                            errornum++;//达到错误值的次数
                        }
                    }
                    if (num < memwarntime)
                    {
                        memvalue = "内存正常;\n\r";
                        memsign = "N";

                    }
                    if (num > memwarntime)
                    {
                        memvalue = "内存>" + memwarnvalue + "% 共:" + num + "次;\n\r";
                        memsign = "W";

                    }
                    if (errornum > memerrortime)
                    {
                        memvalue = "内存>" + memerrorvalue + "% 共:" + errornum + "次;\n\r";
                        memsign = "E";

                    }
                    string sql6 = "select details from Status_Histroy where para_name = 'cpu_running' and sign is null";
                    DataTable cpuerrorcount = tool.DbToDatatable(sql6);
                    int numcpu = 0;
                    int errornumcpu = 0;
                    int cpuerrorvalue = int.Parse(tool.readconfig("bj", "cpuerrorvalue"));
                    int cpuerrortime = int.Parse(tool.readconfig("bj", "cpuerrortime"));
                    int cpuwarnvalue = int.Parse(tool.readconfig("jb", "cpuwarnvalue"));
                    int cpuwarntime = int.Parse(tool.readconfig("jb", "cpuwarntime"));
                    for (int i = 0; i < cpuerrorcount.Rows.Count; i++)
                    {
                        int numm = int.Parse(cpuerrorcount.Rows[i][0].ToString());
                        if (numm > cpuwarnvalue)
                        {
                            numcpu++;//达到警告值的次数
                        }
                        if (numm > cpuerrorvalue)
                        {
                            errornumcpu++;//达到错误值的次数
                        }
                    }
                    if (numcpu < cpuwarntime)
                    {
                        cpuvalue = "正常;\n\r";
                        cpusign = "N";

                    }
                    if (numcpu > cpuwarntime)
                    {
                        cpuvalue = "CPU>" + cpuwarnvalue + "% 共:" + numcpu + "次;\n\r";
                        cpusign = "W";

                    }
                    if (errornumcpu > cpuerrortime)
                    {
                        cpuvalue = "CPU>" + cpuerrorvalue + "% 共:" + errornumcpu + "次;\n\r";
                        cpusign = "E";

                    }
                    if (cpusign == "N" && memsign == "N")
                    {
                        string sql10 = "update Status_Now set para_value='正常',flag ='N',details = '" + cpuvalue + "\n\r" + "参数设置值:" + "\n\r" + cpurecomond + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'";
                        tool.AccessDbclass(sql10);
                    }
                    else
                    {
                        if (cpusign == "E" || memsign == "E")
                        {
                            string sql10 = "update Status_Now set para_value='错误',flag ='E',details = '" + cpuvalue + memvalue + "\n\r" + "参数设置值:" + "\n\r" + cpurecomond + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'";
                            tool.AccessDbclass(sql10);

                        }
                        else
                        {
                            string sql10 = "update Status_Now set para_value='警告',flag ='W',details = '" + cpuvalue + memvalue + "\n\r" + "参数设置值:" + "\n\r" + cpurecomond + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'";
                            tool.AccessDbclass(sql10);

                        }

                    }

            }
        }
Exemplo n.º 5
0
        //ip监控
        public void threadIp(bool is_first, int exec)
        {
            string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool begin = tool.execute_or_not("instrument_connection", db_dir, ip, is_first, exec);
            if (begin == true)
            {
                monitor read = new monitor();
                string[] ss = tool.readconfig("ip");
                foreach (string aa in ss)
                {
                    if (aa != "")
                    {
                        ipList.Add(aa);
                    }
                }
                string ip_detail = "";
                for (int i = 1; i < ipList.Count; i++)
                {
                    if (ipList[i] != "\r\n")
                    {
                        string[] dd = Regex.Split(ipList[i], "#", RegexOptions.IgnoreCase);
                        int start = int.Parse(dd[2]);
                        int end = int.Parse(dd[3]);
                        int crrunt = int.Parse(DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00"));
                        ////textBox4.Text = start.ToString();
                        if (crrunt > start && crrunt < end)
                        {

                            if (!mm.CmdPing(dd[1]))
                            {
                                IpInfo ipinfo = new IpInfo();
                                ipinfo.IpAddress = dd[1];
                                ipinfo.WarningDateTime = DateTime.Now;
                                ipinfo.Iphost = dd[0];
                                ipinfo.PingTimes = 1;//默认第一次
                                ///ping 失败以后累加个数,如果第一次ping失败,先累加,达到一定量以后再发送邮件
                                ///
                                string str5 = System.Windows.Forms.Application.StartupPath;
                                string a = str5 + "\\db.accdb";
                                Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                                db.AccessDbClass2(a);
                                string egg = "E";
                                string value = dd[0] + "的ip:" + dd[1] + "连接不通";
                                string sql11 = "insert into Status_Histroy (para_name,details,flag,create_date) values ('instrument_connection','" + value + "','" + egg + "','" + DateTime.Now + "')";
                                bool ee = db.ExecuteSQLNonquery(sql11);

                            }
                            string value3 = dd[0] + "的ip:" + dd[1] + "连接不通";
                            string sql4 = "select count(*) from Status_Histroy where details = '" + value3 + "' and sign is null";
                            DataTable count = tool.DbToDatatable(sql4);
                            int num = int.Parse(count.Rows[0][0].ToString());
                            int warntime = int.Parse(tool.readconfig("jb", "netwarn"));
                            int errortime = int.Parse(tool.readconfig("bj", "neterror"));
                            string value11="";
                            if (num > warntime)
                            {
                                value11 = dd[0] + "的ip:" + dd[1] + "有" + num + "次连接不通;\n\r";
                                string sql3 = "update Status_Now set para_value='警告',create_date = '" + DateTime.Now + "',flag = 'W' where para_name = 'instrument_connection'";
                                tool.AccessDbclass(sql3);

                            }
                            if (num > errortime)
                            {
                                value11 = dd[0] + "的ip:" + dd[1] + "有" + num + "次连接不通;\n\r";
                                string sql3 = "update Status_Now set para_value='错误',create_date = '" + DateTime.Now + "',flag = 'E' where para_name = 'instrument_connection'";
                                tool.AccessDbclass(sql3);

                            }
                            ip_detail += value11;

                        }

                    }
                }
                if (ip_detail =="")
                {
                    ip_detail = "网络正常";
                }
                string sql12 = "update Status_Now set details ='" + ip_detail + "' where para_name = 'instrument_connection'";
                tool.AccessDbclass(sql12);
            }

            ipList.Clear();
        }
Exemplo n.º 6
0
        //硬盘监控
        public void threadDisk(bool is_first, int exec)
        {
            string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool begin = tool.execute_or_not("disk_size", db_dir, disk, is_first, exec);
            if (begin == true)
            {
                monitor mtt = new monitor();
                List<string> driverList = mtt.getFixDisk();//获取硬盘列表
                string cd = "";
                foreach (string driver in driverList)
                {
                    float per = mtt.getDiskFreePercent(driver);
                    string drive = driver.Substring(0, 1);

                    DriverInfo driverInfo = new DriverInfo();
                    driverInfo.WarningDrivers = driver;
                    driverInfo.WarningValue = per;
                    driverInfo.WarningDateTime = DateTime.Now;

                    cd += driverInfo.WarningDrivers.Substring(0, 1) + ": " + driverInfo.WarningValue.ToString("0") + "G;\r\n";
                    int csizewarn = int.Parse(tool.readconfig("jb", "Cwarn"));
                    int dsizewarn = int.Parse(tool.readconfig("jb", "Dwarn"));
                    int esizewarn = int.Parse(tool.readconfig("jb", "Ewarn"));
                    int fsizewarn = int.Parse(tool.readconfig("jb", "Fwarn"));
                    int csizeerror = int.Parse(tool.readconfig("bj", "Cerror"));
                    int dsizeerror = int.Parse(tool.readconfig("bj", "Derror"));
                    int esizeerror = int.Parse(tool.readconfig("bj", "Eerror"));
                    int fsizeerror = int.Parse(tool.readconfig("bj", "Ferror"));
                    ////textBox2.Text = csizewarn;
                    if ((drive == "C" && per < csizeerror) || (drive == "D" && per < dsizeerror) || (drive == "E" && per < esizeerror) || (drive == "F" && per < fsizeerror))
                    {
                        WarningListErrorOfDisk.Add(driverInfo);//达到报错条件硬盘

                    }
                    if ((drive == "C" && per < csizewarn) || (drive == "D" && per < dsizewarn) || (drive == "E" && per < esizewarn) || (drive == "F" && per < fsizewarn))
                    {
                        WarningListWarnOfDisk.Add(driverInfo);//达到警告条件硬盘

                    }

                }
                string str5 = System.Windows.Forms.Application.StartupPath;
                string a = str5 + "\\db.accdb";
                Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                db.AccessDbClass2(a);
                ////textBox1.Text = c;

                string sql3 = "update Status_Now set details ='" + cd + "\n\r" + "参数设置值:" + "\n\r" + diskrecomond + "',create_date = '" + DateTime.Now + "' where para_name = 'disk_size'";

                bool dd = db.ExecuteSQLNonquery(sql3);

                string fgg = "";
                if (WarningListWarnOfDisk.Count == 0 && WarningListErrorOfDisk.Count == 0) //正常
                {
                    fgg = "N";
                    string sql4 = "update Status_Now set para_value='正常',flag ='N' where para_name = 'disk_size'";
                    bool cc = db.ExecuteSQLNonquery(sql4);
                    //////textBox3.Text = cc.ToString();
                }
                if (WarningListWarnOfDisk.Count > 0) //大于设置警告值
                {
                    fgg = "W";
                    string sql4 = "update Status_Now set para_value='警告',flag ='W' where para_name = 'disk_size'";
                    bool cc = db.ExecuteSQLNonquery(sql4);
                    //////textBox3.Text = cc.ToString();
                }
                if (WarningListErrorOfDisk.Count > 0) //大于设置错误值
                {
                    fgg = "E";
                    string sql4 = "update Status_Now set para_value='错误',flag ='E' where para_name = 'disk_size'";
                    bool cc = db.ExecuteSQLNonquery(sql4);
                    //////textBox3.Text = cc.ToString();
                }
                if (WarningListWarnOfDisk.Count > 0 || WarningListErrorOfDisk.Count > 0)
                {
                    string sql11 = "insert into Status_Histroy (para_name,details,flag,create_date) values ('disk_size','" + cd + "','" + fgg + "','" + DateTime.Now + "')";
                    bool ee = db.ExecuteSQLNonquery(sql11);
                    ////textBox3.Text = ee.ToString();
                }
            }
        }
Exemplo n.º 7
0
        //cpu监控
        public void threadCpu(bool is_first, int exec)
        {
            string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool begin = tool.execute_or_not("cpu_running", db_dir, cpumem, is_first, exec);
            if (begin == true)
            {
                monitor cpu = new monitor();
                float cpuValue = cpu.getCpuUsedPercent();
                int perOfCpu = int.Parse(cpuValue.ToString().Split('.').ElementAt(0));
                RamCpuInfo ramCpuInfo = new RamCpuInfo();
                ramCpuInfo.WarningDateTime = DateTime.Now;
                ramCpuInfo.WarningValue = perOfCpu;
                int cpuwarnvalue = int.Parse(tool.readconfig("jb", "cpuwarnvalue"));
                if (perOfCpu >= cpuwarnvalue)
                {
                    string str5 = System.Windows.Forms.Application.StartupPath;
                    string a = str5 + "\\db.accdb";
                    Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                    db.AccessDbClass2(a);
                    string sql11 = "insert into Status_Histroy (para_name,details,create_date) values ('cpu_running','" + perOfCpu + "','" + DateTime.Now + "')";
                    bool ee = db.ExecuteSQLNonquery(sql11);
                    ////textBox3.Text = ee.ToString();

                }
            }
        }
Exemplo n.º 8
0
        //ip监控
        public void threadIp(bool is_first, int exec)
        {
            string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool   begin  = tool.execute_or_not("instrument_connection", db_dir, ip, is_first, exec);

            if (begin == true)
            {
                monitor  read = new monitor();
                string[] ss   = tool.readconfig("ip");
                foreach (string aa in ss)
                {
                    if (aa != "")
                    {
                        ipList.Add(aa);
                    }
                }
                string ip_detail = "";
                for (int i = 1; i < ipList.Count; i++)
                {
                    if (ipList[i] != "\r\n")
                    {
                        string[] dd     = Regex.Split(ipList[i], "#", RegexOptions.IgnoreCase);
                        int      start  = int.Parse(dd[2]);
                        int      end    = int.Parse(dd[3]);
                        int      crrunt = int.Parse(DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00"));
                        ////textBox4.Text = start.ToString();
                        if (crrunt > start && crrunt < end)
                        {
                            if (!mm.CmdPing(dd[1]))
                            {
                                IpInfo ipinfo = new IpInfo();
                                ipinfo.IpAddress       = dd[1];
                                ipinfo.WarningDateTime = DateTime.Now;
                                ipinfo.Iphost          = dd[0];
                                ipinfo.PingTimes       = 1;//默认第一次
                                ///ping 失败以后累加个数,如果第一次ping失败,先累加,达到一定量以后再发送邮件
                                ///
                                string str5 = System.Windows.Forms.Application.StartupPath;
                                string a    = str5 + "\\db.accdb";
                                Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                                db.AccessDbClass2(a);
                                string egg   = "E";
                                string value = dd[0] + "的ip:" + dd[1] + "连接不通";
                                string sql11 = "insert into Status_Histroy (para_name,details,flag,create_date) values ('instrument_connection','" + value + "','" + egg + "','" + DateTime.Now + "')";
                                bool   ee    = db.ExecuteSQLNonquery(sql11);
                            }
                            string    value3    = dd[0] + "的ip:" + dd[1] + "连接不通";
                            string    sql4      = "select count(*) from Status_Histroy where details = '" + value3 + "' and sign is null";
                            DataTable count     = tool.DbToDatatable(sql4);
                            int       num       = int.Parse(count.Rows[0][0].ToString());
                            int       warntime  = int.Parse(tool.readconfig("jb", "netwarn"));
                            int       errortime = int.Parse(tool.readconfig("bj", "neterror"));
                            string    value11   = "";
                            if (num > warntime)
                            {
                                value11 = dd[0] + "的ip:" + dd[1] + "有" + num + "次连接不通;\n\r";
                                string sql3 = "update Status_Now set para_value='警告',create_date = '" + DateTime.Now + "',flag = 'W' where para_name = 'instrument_connection'";
                                tool.AccessDbclass(sql3);
                            }
                            if (num > errortime)
                            {
                                value11 = dd[0] + "的ip:" + dd[1] + "有" + num + "次连接不通;\n\r";
                                string sql3 = "update Status_Now set para_value='错误',create_date = '" + DateTime.Now + "',flag = 'E' where para_name = 'instrument_connection'";
                                tool.AccessDbclass(sql3);
                            }
                            ip_detail += value11;
                        }
                    }
                }
                if (ip_detail == "")
                {
                    ip_detail = "网络正常";
                }
                string sql12 = "update Status_Now set details ='" + ip_detail + "' where para_name = 'instrument_connection'";
                tool.AccessDbclass(sql12);
            }

            ipList.Clear();
        }
Exemplo n.º 9
0
        public void threadWarnSyslog()
        {
            List <EventLogEntry> eventLogList = new List <EventLogEntry>();
            monitor       mmm           = new monitor();
            List <string> eventTypelist = new List <string>();

            eventTypelist.Add("system");
            eventTypelist.Add("Application");
            eventTypelist.Add("Security");
            foreach (string eventType1 in eventTypelist)
            {
                eventLogList = mmm.getWarnEventLog(eventType1);
                bool found = false;
                foreach (EventLogEntry newEventLog in eventLogList)
                {
                    ////textBox4.Text = newEventLog.Message;
                    foreach (EventLogEntry exsitEventLog in ExsitListOfWarnEventLog)
                    {
                        if (exsitEventLog.TimeGenerated == newEventLog.TimeGenerated &&
                            exsitEventLog.Category == newEventLog.Category &&
                            exsitEventLog.Message == newEventLog.Message &&
                            exsitEventLog.InstanceId == newEventLog.InstanceId &&
                            exsitEventLog.UserName == newEventLog.UserName &&
                            exsitEventLog.MachineName == newEventLog.MachineName) //日志相同的只发送一次
                        {
                            found = true;                                         //找到相同的了
                        }
                    }
                    if (!found)                                   //没找到,添加进去,
                    {
                        ExsitListOfWarnEventLog.Add(newEventLog); //填入已存在列表里
                        eventLogTypeList eventList = new eventLogTypeList();
                        eventList.eventLogEntry = newEventLog;
                        eventList.eventLogType  = eventType1;
                        WarningListOfWarnEventLog.Add(eventList);//发送警报列表里
                    }
                }
                eventLogList.Clear(); //处理完毕,清空
            }

            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();
            StringBuilder sb3 = new StringBuilder();
            StringBuilder sb4 = new StringBuilder();
            StringBuilder sb5 = new StringBuilder();

            if (WarningListOfWarnEventLog.Count > 0)
            {
                eventlogWarnNum += WarningListOfWarnEventLog.Count;
                foreach (eventLogTypeList eventLogType in WarningListOfWarnEventLog)
                {
                    string error   = eventLogType.eventLogType + "日志出现警告!";
                    string message = eventLogType.eventLogEntry.Message;
                    string sb      = eventLogType.eventLogType + message + eventLogType.eventLogEntry.TimeGenerated;
                    string str5    = System.Windows.Forms.Application.StartupPath;
                    string a       = str5 + "\\db.accdb";
                    Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                    db.AccessDbClass2(a);
                    string egg   = "W";
                    string sql11 = "insert into Status_Histroy (para_name,details,flag,create_date,para_value) values ('syslog_warn','" + error + "%','" + egg + "','" + eventLogType.eventLogEntry.TimeGenerated + "','" + message + "')";
                    bool   ee    = db.ExecuteSQLNonquery(sql11);
                }
                WarningListOfWarnEventLog.Clear();
            }
        }
Exemplo n.º 10
0
        //内存监控
        public void threadMem(bool is_first, int exec)
        {
            string memvalue = "内存正常;\n\r";
            string memsign  = "N";
            string cpuvalue = "CPU正常;\n\r";
            string cpusign  = "N";
            string db_dir   = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool   begin    = tool.execute_or_not("memory_running", db_dir, cpumem, is_first, exec);

            if (begin == true)
            {
                monitor mem           = new monitor();
                uint    memValue      = mem.getRamUsePercent();
                int     perOfRam      = int.Parse(memValue.ToString().Split('.').ElementAt(0));
                int     memerrorvalue = int.Parse(tool.readconfig("bj", "memerrorvalue"));
                int     memerrortime  = int.Parse(tool.readconfig("bj", "memerrortime"));
                int     memwarnvalue  = int.Parse(tool.readconfig("jb", "memwarnvalue"));
                int     memwarntime   = int.Parse(tool.readconfig("jb", "memwarntime"));
                if (perOfRam >= memwarnvalue)
                {
                    RamCpuInfo ramCpuInfo = new RamCpuInfo();
                    ramCpuInfo.WarningDateTime = DateTime.Now;
                    ramCpuInfo.WarningValue    = perOfRam;
                    WarningListOfMem.Add(ramCpuInfo);
                    string str5 = System.Windows.Forms.Application.StartupPath;
                    string a    = str5 + "\\db.accdb";
                    Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                    db.AccessDbClass2(a);
                    string sql11 = "insert into Status_Histroy (para_name,details,create_date) values ('memory_running','" + perOfRam + "','" + DateTime.Now + "')";
                    bool   ee    = db.ExecuteSQLNonquery(sql11);
                }
                ////textBox3.Text = ee.ToString();
                string    sql5          = "select details from Status_Histroy where para_name = 'memory_running' and sign is null";
                DataTable memerrorcount = tool.DbToDatatable(sql5);
                int       num           = 0;
                int       errornum      = 0;
                for (int i = 0; i < memerrorcount.Rows.Count; i++)
                {
                    int numm = int.Parse(memerrorcount.Rows[i][0].ToString());
                    if (numm > memwarnvalue)
                    {
                        num++;    //达到警告值的次数
                    }
                    if (numm > memerrorvalue)
                    {
                        errornum++;    //达到错误值的次数
                    }
                }
                if (num < memwarntime)
                {
                    memvalue = "内存正常;\n\r";
                    memsign  = "N";
                }
                if (num > memwarntime)
                {
                    memvalue = "内存>" + memwarnvalue + "% 共:" + num + "次;\n\r";
                    memsign  = "W";
                }
                if (errornum > memerrortime)
                {
                    memvalue = "内存>" + memerrorvalue + "% 共:" + errornum + "次;\n\r";
                    memsign  = "E";
                }
                string    sql6          = "select details from Status_Histroy where para_name = 'cpu_running' and sign is null";
                DataTable cpuerrorcount = tool.DbToDatatable(sql6);
                int       numcpu        = 0;
                int       errornumcpu   = 0;
                int       cpuerrorvalue = int.Parse(tool.readconfig("bj", "cpuerrorvalue"));
                int       cpuerrortime  = int.Parse(tool.readconfig("bj", "cpuerrortime"));
                int       cpuwarnvalue  = int.Parse(tool.readconfig("jb", "cpuwarnvalue"));
                int       cpuwarntime   = int.Parse(tool.readconfig("jb", "cpuwarntime"));
                for (int i = 0; i < cpuerrorcount.Rows.Count; i++)
                {
                    int numm = int.Parse(cpuerrorcount.Rows[i][0].ToString());
                    if (numm > cpuwarnvalue)
                    {
                        numcpu++;    //达到警告值的次数
                    }
                    if (numm > cpuerrorvalue)
                    {
                        errornumcpu++;    //达到错误值的次数
                    }
                }
                if (numcpu < cpuwarntime)
                {
                    cpuvalue = "正常;\n\r";
                    cpusign  = "N";
                }
                if (numcpu > cpuwarntime)
                {
                    cpuvalue = "CPU>" + cpuwarnvalue + "% 共:" + numcpu + "次;\n\r";
                    cpusign  = "W";
                }
                if (errornumcpu > cpuerrortime)
                {
                    cpuvalue = "CPU>" + cpuerrorvalue + "% 共:" + errornumcpu + "次;\n\r";
                    cpusign  = "E";
                }
                if (cpusign == "N" && memsign == "N")
                {
                    string sql10 = "update Status_Now set para_value='正常',flag ='N',details = '" + cpuvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'";
                    tool.AccessDbclass(sql10);
                }
                else
                {
                    if (cpusign == "E" || memsign == "E")
                    {
                        string sql10 = "update Status_Now set para_value='错误',flag ='E',details = '" + cpuvalue + memvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'";
                        tool.AccessDbclass(sql10);
                    }
                    else
                    {
                        string sql10 = "update Status_Now set para_value='警告',flag ='W',details = '" + cpuvalue + memvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'";
                        tool.AccessDbclass(sql10);
                    }
                }
            }
        }
Exemplo n.º 11
0
        //硬盘监控

        public void threadDisk(bool is_first, int exec)
        {
            string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb";
            bool   begin  = tool.execute_or_not("disk_size", db_dir, disk, is_first, exec);

            if (begin == true)
            {
                monitor       mtt        = new monitor();
                List <string> driverList = mtt.getFixDisk();//获取硬盘列表
                string        cd         = "";
                foreach (string driver in driverList)
                {
                    float  per   = mtt.getDiskFreePercent(driver);
                    string drive = driver.Substring(0, 1);

                    DriverInfo driverInfo = new DriverInfo();
                    driverInfo.WarningDrivers  = driver;
                    driverInfo.WarningValue    = per;
                    driverInfo.WarningDateTime = DateTime.Now;

                    cd += driverInfo.WarningDrivers.Substring(0, 1) + ": " + driverInfo.WarningValue.ToString("0") + "G;\r\n";
                    int csizewarn  = int.Parse(tool.readconfig("jb", "Cwarn"));
                    int dsizewarn  = int.Parse(tool.readconfig("jb", "Dwarn"));
                    int esizewarn  = int.Parse(tool.readconfig("jb", "Ewarn"));
                    int fsizewarn  = int.Parse(tool.readconfig("jb", "Fwarn"));
                    int csizeerror = int.Parse(tool.readconfig("bj", "Cerror"));
                    int dsizeerror = int.Parse(tool.readconfig("bj", "Derror"));
                    int esizeerror = int.Parse(tool.readconfig("bj", "Eerror"));
                    int fsizeerror = int.Parse(tool.readconfig("bj", "Ferror"));
                    ////textBox2.Text = csizewarn;
                    if ((drive == "C" && per < csizeerror) || (drive == "D" && per < dsizeerror) || (drive == "E" && per < esizeerror) || (drive == "F" && per < fsizeerror))
                    {
                        WarningListErrorOfDisk.Add(driverInfo);//达到报错条件硬盘
                    }
                    if ((drive == "C" && per < csizewarn) || (drive == "D" && per < dsizewarn) || (drive == "E" && per < esizewarn) || (drive == "F" && per < fsizewarn))
                    {
                        WarningListWarnOfDisk.Add(driverInfo);//达到警告条件硬盘
                    }
                }
                string str5 = System.Windows.Forms.Application.StartupPath;
                string a    = str5 + "\\db.accdb";
                Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1();
                db.AccessDbClass2(a);
                ////textBox1.Text = c;

                string sql3 = "update Status_Now set details ='" + cd + "',create_date = '" + DateTime.Now + "' where para_name = 'disk_size'";

                bool dd = db.ExecuteSQLNonquery(sql3);


                string fgg = "";
                if (WarningListWarnOfDisk.Count == 0 && WarningListErrorOfDisk.Count == 0) //正常
                {
                    fgg = "N";
                    string sql4 = "update Status_Now set para_value='正常',flag ='N' where para_name = 'disk_size'";
                    bool   cc   = db.ExecuteSQLNonquery(sql4);
                    //////textBox3.Text = cc.ToString();
                }
                if (WarningListWarnOfDisk.Count > 0) //大于设置警告值
                {
                    fgg = "W";
                    string sql4 = "update Status_Now set para_value='警告',flag ='W' where para_name = 'disk_size'";
                    bool   cc   = db.ExecuteSQLNonquery(sql4);
                    //////textBox3.Text = cc.ToString();
                }
                if (WarningListErrorOfDisk.Count > 0) //大于设置错误值
                {
                    fgg = "E";
                    string sql4 = "update Status_Now set para_value='错误',flag ='E' where para_name = 'disk_size'";
                    bool   cc   = db.ExecuteSQLNonquery(sql4);
                    //////textBox3.Text = cc.ToString();
                }
                if (WarningListWarnOfDisk.Count > 0 || WarningListErrorOfDisk.Count > 0)
                {
                    string sql11 = "insert into Status_Histroy (para_name,details,flag,create_date) values ('disk_size','" + cd + "','" + fgg + "','" + DateTime.Now + "')";
                    bool   ee    = db.ExecuteSQLNonquery(sql11);
                    ////textBox3.Text = ee.ToString();
                }
            }
        }