Accessing SNMP trap information using WMI
-
Hi All, I am trying to retrieve the SNMP TRAP information using WMI calls like
Try Dim connection As New ConnectionOptions() ' connection.Username = "xxx" 'connection.Password = "yyyy" 'connection.Authority = "ntlmdomain:DOMAIN" Dim scope As New ManagementScope("\\localhost\root\snmp\localhost", connection) scope.Connect() Dim query As New WqlEventQuery("SELECT * FROM SnmpNotification") Dim watcher As New ManagementEventWatcher(scope, query) Console.WriteLine("Waiting for an event on FullComputerName ...") Dim eventObj As ManagementBaseObject = watcher.WaitForNextEvent() watcher.Start() Console.WriteLine("{0} event occurred.", eventObj("__CLASS")) console.WriteLine("{0} Community name---> .", eventObj("Community")) 'Display information from the event Console.WriteLine("Process {0} has created, path is: ", eventObj("__PATH")) Console.WriteLine("Property count {0}", eventObj("__PROPERTY_COUNT")) Console.WriteLine("Relative path {0} ", eventObj("__RELPATH")) Console.WriteLine("Server {0} ", eventObj("__SERVER")) Console.WriteLine("SUPERCLASS {0} ", eventObj("__SUPERCLASS")) Console.WriteLine("AgentAddress {0} ", eventObj("AgentAddress")) Console.WriteLine("AgentTransportAddress {0} ", eventObj("AgentTransportAddress")) Console.WriteLine("AgentTransportProtocol {0} ", eventObj("AgentTransportProtocol")) Console.WriteLine("Identification {0} ", eventObj("Identification")) Console.WriteLine("TimeStamp {0} ", eventObj("TimeStamp")) Console.WriteLine("VarBindList {0} ", eventObj("VarBindList")) 'Console.WriteLine("Enterprise {0} ", eventObj("Enterprise")) ' Cancel the event subscription watcher.Stop() Close() Catch err As ManagementException MessageBox.Show("An error occurred while trying to receive an event: " & err.Message) Catch unauthorizedErr As System.UnauthorizedAccessException MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message) End Try
Output is like SnmpV1Notification event occurred. public Community name---> . Process has created, path is: Property count 9 Relative path Server SUPERCLASS SnmpNotification AgentAddress 127.0.0.1 AgentTransportAddress 127.0.0.1 AgentTransportProtocol IP Identification 1.3.6.1.4.1.393.200.50.66.0.2 TimeStamp 9 Here I am unable get to the text message inside the trap. Does anybody know how to retrieve it? -
Hi All, I am trying to retrieve the SNMP TRAP information using WMI calls like
Try Dim connection As New ConnectionOptions() ' connection.Username = "xxx" 'connection.Password = "yyyy" 'connection.Authority = "ntlmdomain:DOMAIN" Dim scope As New ManagementScope("\\localhost\root\snmp\localhost", connection) scope.Connect() Dim query As New WqlEventQuery("SELECT * FROM SnmpNotification") Dim watcher As New ManagementEventWatcher(scope, query) Console.WriteLine("Waiting for an event on FullComputerName ...") Dim eventObj As ManagementBaseObject = watcher.WaitForNextEvent() watcher.Start() Console.WriteLine("{0} event occurred.", eventObj("__CLASS")) console.WriteLine("{0} Community name---> .", eventObj("Community")) 'Display information from the event Console.WriteLine("Process {0} has created, path is: ", eventObj("__PATH")) Console.WriteLine("Property count {0}", eventObj("__PROPERTY_COUNT")) Console.WriteLine("Relative path {0} ", eventObj("__RELPATH")) Console.WriteLine("Server {0} ", eventObj("__SERVER")) Console.WriteLine("SUPERCLASS {0} ", eventObj("__SUPERCLASS")) Console.WriteLine("AgentAddress {0} ", eventObj("AgentAddress")) Console.WriteLine("AgentTransportAddress {0} ", eventObj("AgentTransportAddress")) Console.WriteLine("AgentTransportProtocol {0} ", eventObj("AgentTransportProtocol")) Console.WriteLine("Identification {0} ", eventObj("Identification")) Console.WriteLine("TimeStamp {0} ", eventObj("TimeStamp")) Console.WriteLine("VarBindList {0} ", eventObj("VarBindList")) 'Console.WriteLine("Enterprise {0} ", eventObj("Enterprise")) ' Cancel the event subscription watcher.Stop() Close() Catch err As ManagementException MessageBox.Show("An error occurred while trying to receive an event: " & err.Message) Catch unauthorizedErr As System.UnauthorizedAccessException MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message) End Try
Output is like SnmpV1Notification event occurred. public Community name---> . Process has created, path is: Property count 9 Relative path Server SUPERCLASS SnmpNotification AgentAddress 127.0.0.1 AgentTransportAddress 127.0.0.1 AgentTransportProtocol IP Identification 1.3.6.1.4.1.393.200.50.66.0.2 TimeStamp 9 Here I am unable get to the text message inside the trap. Does anybody know how to retrieve it?