الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف أعمل برنامج يستخدم بروتوكول ال snmp للمراقبة؟

مغلق
بدأه Pixar في 26 أكتوبر 2006 · 0 رد · 1,492 مشاهدة · في برمجة الشبكات والتطبيقات الموزعة
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكم

توجد عندي مشكلة في البرنامج الذي قمت بعمله وهو برنامج يستخدم بروتوكول ال snmp لجلب معلومات وعمل مراقبة على عناصر موجودة في الشبكة سواء كانت اجهزة عادية او cisco devices وانا استخدم لغة c#.net v2.0 and ms access

المشكلة انه برنامجي يشتغل بشكل جيد في بعض الاحيان ولكن في بعض الاحيان عندما احاول جلب بعض المعلومات من اي عنصر في الشبكة فأن البرنامج يتوقف عن العمل وتظهر عند ال debugger بعض الاخطاء كهذه الرسالة

The CLR has been unable to transition from COM context 0x1a2008 to COM context 0x1a2178 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

بلاضافة لبعض الاخطاء حول ال marshaling وطبعا البرنامج لا يشير الى مكانها في الكود

هذا هو جزء من الكود الخاص بجلب المعلومات التي ليس لها علاقة برسم ال graphs هو فقط يجلب ويطبع النتائج في listview"detailed" والذي يسبب كثيرا في وقوع المشكلة ولم اجد حلا له

private void Buttom_Refresh_Click(object sender, EventArgs e)
		{
			Label_Status.Text = "fetching SNMP OIDs from the Agent.....Please Wait";
			LV_Info.Items.Clear(); 
			snmpObject_Main.Port=(int)MonitorDataSet.Tables[1].Rows[rowNumber_M][4];
			snmpObject_Main.ProtocolVersion = (int)MonitorDataSet.Tables[1].Rows[rowNumber_M][6];
			snmpObject_Main.Initialize();
			if(snmpObject_Main.LastError==0)
			{
				snmpObject_Main.Open(MonitorDataSet.Tables[1].Rows[rowNumber_M][3].ToString(), MonitorDataSet.Tables[1].Rows[rowNumber_M][5].ToString());
				if (snmpObject_Main.LastError == 0)
				{ 
					if (TreeView_SensorList.SelectedNode.FullPath.Contains("PC\\"))
					{
						if (CLB_M.GetItemChecked(0))
							GeneralInfo();

						if (CLB_M.GetItemChecked(1))
							SystemInfo();

						if (CLB_M.GetItemChecked(2))
							NetworkingInfo();

						if (CLB_M.GetItemChecked(3))
							SNMPInfo();
					}
				}
				snmpObject_Main.Close();
			}
			snmpObject_Main.Clear();
			snmpObject_Main.Shutdown();
			LV_Info.Visible = true;
			Label_Status.Text = "Refreshing operation success.";

		}

		private void GeneralInfo()
		{

			ListViewItem item1 = new ListViewItem();
			string bb = snmpObject_Main.GetNext("1.3.6.1.2.1.1.1");
			item1.Text = "Hardware and software";
			item1.BackColor = Color.Red;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1=  new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.1.4");
			item1.Text = "Agent Contact";
			item1.BackColor = Color.Red;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.1.5");
			item1.Text = "Agent Name";
			item1.BackColor = Color.Red;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.1.6");
			item1.Text = "Agent Location";
			item1.BackColor = Color.Red;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;
		}


		private void SystemInfo()
		{ 
			ListViewItem item1 = new ListViewItem();
			item1.Text = "System up time";
			item1.BackColor = Color.Chocolate;
			string bb = snmpObject_Main.GetNext("1.3.6.1.2.1.25.1.1");
			uint b = uint.Parse((snmpObject_Main.Get(bb))) / 1000;
			item1.SubItems.Add(string.Format("Day: {0}, Hour: {1}, Minute(s): {2}, Second(s): {3}", TimeSpan.FromSeconds(b).Days, TimeSpan.FromSeconds(b).Hours, TimeSpan.FromSeconds(b).Minutes, TimeSpan.FromSeconds(b).Seconds));
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.25.1.6");
			item1.Text = "Running processes on the Agent";
			item1.BackColor = Color.Chocolate;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.25.2.2");
			item1.Text = "Agent RAM";
			item1.BackColor = Color.Chocolate;
			float RAMresult = Convert.ToSingle(snmpObject_Main.Get(bb)) / 1024;
			item1.SubItems.Add(RAMresult.ToString()+" MB");
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			byte counter = 0;
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.25.2.3.1.1");
			snmpObject_Main.Get(bb);
			while (snmpObject_Main.GetType() != snmpObject_Main.asASN_OBJECTIDENTIFIER)
			{

				counter+=1;
				bb = snmpObject_Main.GetNext(bb); 
				snmpObject_Main.Get(bb);

			}
			item1.Text = "Number of storage elements";
			item1.BackColor = Color.Chocolate;
			item1.SubItems.Add(counter.ToString());
			LV_Info.Items.Add(item1);
			item1 = null;


			bb = "1.3.6.1.2.1.25.2.3.1.3";
			string bb2 = "1.3.6.1.2.1.25.2.3.1.5";
			string bb3 = "1.3.6.1.2.1.25.2.3.1.6";
			string bb4 = "1.3.6.1.2.1.25.2.3.1.4";
			for (uint i = 0; i < counter; i++)
			{
				item1 = new ListViewItem();
				bb = snmpObject_Main.GetNext(bb);  
				bb2 = snmpObject_Main.GetNext(bb2);
				bb3 = snmpObject_Main.GetNext(bb3);
				bb4 = snmpObject_Main.GetNext(bb4);
				float pp4 = Convert.ToSingle(snmpObject_Main.Get(bb4));
				float pp2 = Convert.ToSingle(snmpObject_Main.Get(bb2));
				float pp5 = pp4 * pp2;
				float pp3 = Convert.ToSingle(snmpObject_Main.Get(bb3));
				float pp6 = pp4 * pp3;
				string giga, mega;
				if (pp5 >= 1000000000)
				{ 
					giga = " GByte"; 
					pp5 = pp5 / 1000000000; 
				}
				else
					if (pp5 >= 1000000) 
					{ 
						giga = " MByte"; 
						pp5 = pp5 / 1000000; 
					}
					else
						if (pp5 >= 1000) 
						{ 
							giga = " KByte"; 
							pp5 = pp5 / 1000; 
						}
						else 
							giga = "Byte"; 
				if (pp6 >= 1000000000) 
				{ 
					mega = " GByte"; 
					pp6 = pp6 / 1000000000; 
				}
				else
					if (pp6 >= 1000000) 
					{ 
						mega = " MByte"; 
						pp6 = pp6 / 1000000; 
					}
					else
						if (pp6 >= 1000) 
						{ 
							mega = " KByte"; 
							pp6 = pp6 / 1000; 
						}
						else 
							mega = " Byte";
				uint j = i + 1;

				item1.Text = "Storage :" + j.ToString();
				item1.BackColor = Color.Chocolate;
				item1.SubItems.Add(snmpObject_Main.Get(bb).ToString() + "	 ,Total Size: " + pp5.ToString() + giga + "  ,Used: " + pp6.ToString() + mega);
				LV_Info.Items.Add(item1);
				item1 = null;
			}
		}

		private void NetworkingInfo()
		{

			ListViewItem item1 = new ListViewItem();
			string bb = snmpObject_Main.GetNext("1.3.6.1.2.1.1.3");
			item1.Text = "Network uptime";
			item1.BackColor = Color.DarkBlue;
			uint b = uint.Parse((snmpObject_Main.Get(bb))) / 1000;
			item1.SubItems.Add(string.Format("Day: {0}, Hour: {1}, Minute(s): {2}, Second(s): {3}", TimeSpan.FromSeconds(b).Days, TimeSpan.FromSeconds(b).Hours, TimeSpan.FromSeconds(b).Minutes, TimeSpan.FromSeconds(b).Seconds));
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.4.1.77.1.4.1");
			item1.Text = "Workgroup";
			item1.BackColor = Color.DarkBlue;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.2.1");
			byte counter = Convert.ToByte(snmpObject_Main.Get(bb));
			item1.Text = "Number of system interfaces";
			item1.BackColor = Color.DarkBlue;
			item1.SubItems.Add(counter.ToString());
			LV_Info.Items.Add(item1);
			item1 = null;


			bb = "1.3.6.1.2.1.2.2.1.2";
			string bb2 = "1.3.6.1.2.1.2.2.1.5";
			string packet_in = "1.3.6.1.2.1.2.2.1.10";
			string packet_out = "1.3.6.1.2.1.2.2.1.16";
			uint speed = 0; 
			string bba = bb,giga;
			for (uint R = 0; R < counter; R++)
			{ 
				bb = bba;
				bb = snmpObject_Main.GetNext(bb);
				bb2 = snmpObject_Main.GetNext(bb2);
				packet_in = snmpObject_Main.GetNext(packet_in);
				packet_out = snmpObject_Main.GetNext(packet_out);
				speed = uint.Parse(snmpObject_Main.Get(bb2));
				if (speed >= 1000000000) 
				{ 
					giga = " Gbps"; 
					speed = speed / 1000000000; 
				} 
				else
					if (speed >= 1000000) 
					{ 
						giga = " Mbps"; 
						speed = speed / 1000000; 
					}
					else 
						giga = " Kbps";
				uint j = R + 1;
				item1 = new ListViewItem();
				item1.Text = "Interface :" + j.ToString();
				item1.BackColor = Color.DarkBlue;
				item1.SubItems.Add(snmpObject_Main.Get(bb).ToString() + " ,Speed: " + speed + giga);
				bba = bb;
				LV_Info.Items.Add(item1);
				item1 = null;

				item1 = new ListViewItem();
				item1.Text = "Number of packets recieved by the Agent";
				item1.BackColor = Color.DarkBlue;
				float num_Byte1 = (Convert.ToSingle(snmpObject_Main.Get(packet_in)));
				if (num_Byte1 >= 1000000000) 
					{ 
						giga = " GByte"; 
						num_Byte1 = num_Byte1 / 1000000000; 
					}
					else
						if (num_Byte1 >= 1000000) 
						{ 
							giga = " MByte"; 
							num_Byte1 = num_Byte1 / 1000000; 
						}
						else
							if (num_Byte1 >= 1000) 
							{ 
								giga = " KByte"; 
								num_Byte1 = num_Byte1 / 1000; 
							}
							else 
								giga = " Byte"; 

					item1.SubItems.Add(num_Byte1.ToString() + giga);
					LV_Info.Items.Add(item1);
					item1 = null;

					item1 = new ListViewItem();
					item1.Text = "Number of packets transmitted by the Agent";
					item1.BackColor = Color.DarkBlue;
					float num_Byte = Convert.ToSingle(snmpObject_Main.Get(packet_out));
					if (num_Byte >= 1000000000) 
					{ 
						giga = " GByte";
						num_Byte = num_Byte / 1000000000;
					}
					else
						if (num_Byte >= 1000000) 
						{ 
							giga = " MByte"; 
							num_Byte = num_Byte / 1000000; 
						}
						else
							if (num_Byte >= 1000) 
							{ 
								giga = " KByte"; 
								num_Byte = num_Byte / 1000; 
							}
							else 
								giga = " Byte"; 
					item1.SubItems.Add(num_Byte.ToString() + giga);
					LV_Info.Items.Add(item1);
					item1 = null;
			}

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.4.1.77.1.2.26");
			counter = Convert.ToByte(snmpObject_Main.Get(bb));
			item1.Text = "Number of shared resources";
			item1.BackColor = Color.DarkBlue;
			item1.SubItems.Add(counter.ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			bb = "1.3.6.1.4.1.77.1.2.27.1.1";
			bb2 = "1.3.6.1.4.1.77.1.2.27.1.2";
			for (uint i = 0; i < counter; i++)
				{
					bb = snmpObject_Main.GetNext(bb);
					bb2 = snmpObject_Main.GetNext(bb2);
					item1 = new ListViewItem();
					uint j = i + 1;
					item1 = new ListViewItem();
					item1.Text = "Resource :" + j.ToString();
					item1.BackColor = Color.DarkBlue;
					item1.SubItems.Add("Name: " + snmpObject_Main.Get(bb).ToString() + "	 ,Path: " + snmpObject_Main.Get(bb2).ToString());
					LV_Info.Items.Add(item1);
					item1 = null;
				}
		}

		private void SNMPInfo()
		{
			ListViewItem item1 = new ListViewItem();
			string bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.1");
			item1.Text = "Number of SNMP input packets";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.2");
			item1.Text = "Number of SNMP output packets";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.15");
			item1.Text = "Number of Input GET Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.16");
			item1.Text = "Number of Input GETNEXT Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.18");
			item1.Text = "Number of Input GETRESPONSE Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.17");
			item1.Text = "Number of Input SET Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.19");
			item1.Text = "Number of Accepted Input Traps";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.25");
			item1.Text = "Number of Output GET Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.26");
			item1.Text = "Number of Output GETNEXT Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.27");
			item1.Text = "Number of Output SET Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.28");
			item1.Text = "Number of Output GETRESPONSE Requests";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

			item1 = new ListViewItem();
			bb = snmpObject_Main.GetNext("1.3.6.1.2.1.11.29");
			item1.Text = "Number of Generated Input Traps";
			item1.BackColor = Color.DarkGreen;
			item1.SubItems.Add(snmpObject_Main.Get(bb).ToString());
			LV_Info.Items.Add(item1);
			item1 = null;

		}

والدالة التي عندما اخفيها غالبا ما يشتغل البرنامج بشكل جيد هي

private void SystemInfo()

فلا ادري ما هي المشكلة

هل هناك خطوات يجب ان اتبعها عند التعامل مع برمجة الشبكات

استخدمت ملف ال dll الخاص ببروتوكول ال snmp من الشركة

activesocket

ارجوا منكم المساعدة

هذا الموضوع مغلق.

مواضيع مشابهة