private void auto_monitor() { try { var allhost = from obj in db.host_command where (obj.adapter.Equals("telnet") && obj.os.Equals("aix") && obj.strcommand.Equals("df -g")) select obj; foreach (host_command onehost in allhost) { telnet_text = ""; //attenion , must clear previous telnet text telnet1_logon(onehost.hostname); //telnet hostname Thread.Sleep(1000 * 10); //延迟10秒 DateTime thistime = DateTime.Now; //找到这个主机的规则 var q = from obj in db.rule_aix_df where obj.hostname.Equals(onehost.hostname) select obj; foreach (rule_aix_df s in q) { List <string> list = str_line(s.hostname, telnet_text, s.strhead, s.strtail); //write DB log_aix_df one = new log_aix_df(); one.savetime = thistime; one.hostname = list[0]; one.filesystem = list[1]; one.GBblocks = list[2]; one.diskfree = list[3]; one.diskused = list[4]; one.iused = list[5]; one.iusedpercent = list[6]; one.mounted = list[7]; //check Alarm string temp = list[4].Replace("%", ""); if (i(temp) > 90) { one.alarm_checked = "alarm"; } db.log_aix_df.Add(one); } worklog(onehost.hostname + " info db saved."); } db.SaveChanges(); } catch (Exception ex) { worklog(ex.Message); } }
//////////////////////// ////// monitor ////// //////////////////////// private void listView_host_DoubleClick(object sender, EventArgs e) { try { if (this.listView_host.SelectedItems.Count == 0) { return; } telnet_text = ""; listView_handstream.Items.Clear(); //fdjeccprd1 string hostone = listView_host.FocusedItem.Text; // MessageBox.Show(hostone); telnet_text = ""; //attenion , must clear previous telnet text telnet1_logon(hostone); // textBox1.Text = telnet_text; DateTime thistime = DateTime.Now; //找到这个主机的规则 var q = from obj in db.rule_aix_df where obj.hostname.Equals(hostone) select obj; foreach (rule_aix_df s in q) { List <string> list = str_line(s.hostname, telnet_text, s.strhead, s.strtail); //listview控件显示 ListViewItem item = new ListViewItem(); listView_handstream.Items.Add(item); item.Text = list[0]; item.SubItems.Add(list[1]); item.SubItems.Add(list[2]); item.SubItems.Add(list[3]); item.SubItems.Add(list[4]); item.SubItems.Add(list[5]); item.SubItems.Add(list[6]); item.SubItems.Add(list[7]); //write DB log_aix_df one = new log_aix_df(); one.savetime = thistime; one.hostname = list[0]; one.filesystem = list[1]; one.GBblocks = list[2]; one.diskfree = list[3]; one.diskused = list[4]; one.iused = list[5]; one.iusedpercent = list[6]; one.mounted = list[7]; //check Alarm string temp = list[4].Replace("%", ""); if (i(temp) > 90) { item.ForeColor = Color.Red; one.alarm_checked = "alarm"; } db.log_aix_df.Add(one); } db.SaveChanges(); } catch (Exception ex) { worklog(ex.Message); } }