Recieving SNMP traps as WMI events.

Discussion in 'Scripting' started by Andrew Mishechkin, Aug 8, 2008.

  1. Hello All

    I want to recieve SNMP traps as WMI events.
    I have read the next MSDN articles:
    http://msdn.microsoft.com/en-us/library/aa393020.aspx
    http://msdn.microsoft.com/en-us/library/aa393019.aspx
    http://msdn.microsoft.com/en-us/library/ms907028.aspx

    I intend to create the permanent WMI consumer, and I cretated the three
    scripts for this: filter, consumer and script for binding.
    Filter script:
    ------------------------------------------------------
    Option Explicit
    On Error Resume Next

    Dim strComputer
    Dim strNamespace
    Dim objService
    Dim objEventFilterClass
    Dim objEventFilter

    strComputer = "."
    strNamespace = "Root\snmp\SMIR"
    Set objService = GetObject("WinMgmts:\\" & strComputer & "\" & strNamespace)
    Set objEventFilterClass = objService.Get("__EventFilter")
    Set objEventFilter = objEventFilterClass.SpawnInstance_()

    objEventFilter.Name = "TrapMonitor"
    objEventFilter.QueryLanguage = "WQL"
    objEventFilter.Query = "SELECT * FROM SnmpColdStartNotification"
    objEventFilter.Put_()
    -------------------

    Consumer script:
    -----------------------------------------------------
    Option Explicit
    On Error Resume Next

    Dim strComputer
    Dim strNamespace
    Dim objService
    Dim objConsumerClass
    Dim objConsumer

    strComputer = "."
    strNamespace = "Root\snmp\SMIR"
    Set objService = GetObject("WinMgmts:\\" & strComputer & "\" & strNamespace)
    Set objConsumerClass = objService.Get("LogFileEventConsumer")
    Set objConsumer = objConsumerClass.SpawnInstance_()
    objConsumer.Name = "TrapsLog"
    objConsumer.Filename = "C:\Temp\TrapsLog.txt"
    objConsumer.Text = "ôÒÜÐ ÐÏÌÕÞÅÎ"
    objConsumer.Put_()
    --------------------------------------------------

    Binding script:
    ----------------------------------------------------
    Option Explicit
    On Error Resume Next

    Dim strComputer
    Dim strNamespace
    Dim objService
    Dim objEventFilter
    Dim objConsumer
    Dim objBindingClass
    Dim objBindingInstance

    strComputer = "."
    strNamespace = "Root\snmp\SMIR"
    Set objService = GetObject("WinMgmts:\\" & strComputer & "\" & strNamespace)
    Set objEventFilter = objService.Get("__EventFilter.name=""TrapMonitor""")
    Set objConsumer = objService.Get("LogFileEventConsumer.name=""TrapsLog""")
    Set objBindingClass = objService.Get("__FilterToConsumerBinding")
    Set objBindingInstance = objBindingClass.SpawnInstance_()
    objBindingInstance.Filter = objEventFilter.Path_
    objBindingInstance.Consumer = objConsumer.Path_
    objBindingInstance.Put_()
    --------------------------------------------
    I compile mof-file for LogFileEventConsumer and plase into root\snmp\SMIR
    ---
    mofcomp -N:root\snmp\SMIR C:\Windows\System32\Wbem\wbemcons.mof
    ---
    and run my scripts - everything is OK.
    But when SNMP trap is recieving - I have no WMI events. I run temporary
    consumer script from MSDN:
    ---------------------------------------------------------------
    Set objLocator = CreateObject("wbemscripting.swbemlocator")
    Set objServices = objLocator.ConnectServer(, "root\snmp\SMIR")
    set objwbemEventsource = objServices.ExecNotificationQuery("SELECT * FROM
    SnmpLinkUpNotification")
    set objWbemObject = objwbemEventsource.NextEvent()
    wscript.echo "Received " & objWbemObject.path_.class
    for each prop in objWbemObject.properties_
    wscript.echo prop.name & " -- " & prop.value
    next
     
    Andrew Mishechkin, Aug 8, 2008
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.