Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: Power SNMP Backward compatibility
WWSnmp
mithunbabu@gmail.com

From: 1155 Perimeter Center West, GA USA
Posts: 12
Member Since: 06/18/12
posted June 18, 2012 10:27 AM

Hi,

We were using an old version of Dart PowerSNMP(1.2.1.0) for SNMP polling. Recently we shifted to .net V4.0 and we were having trouble with porting the polling system to .net 4.0. We spoke to customer care and they suggested to upgrade and that the issue would be resolved. (http://support.dart.com/postings?topicid=8450#34595).
Now we bought the new version of PowerSNMP for .NET, and looks like the dlls are not backward compatible. Looks like there is change in model itself in the way SNMP polling is happening.
This was the code we had initially-

public static bool GetStandardStatus(string _IPAddress, int _port, string _readCommunity, Dart.PowerSNMP.SnmpVersion _ver)
      {
        Dart.Snmp.Manager _mgr = new Manager();
        try
        {
          _mgr.Timeout = 3000;
          _mgr.Open(0);

          Dart.PowerSNMP.GetMessage _get = new GetMessage { Community = _readCommunity, Version = _ver };

          _get.Variables.Add(new Dart.PowerSNMP.Variable("1.3.6.1.2.1.1.3.0"));
          Dart.PowerSNMP.ResponseMessage _response;
          try
          {
            _response = _mgr.Response(_get, _IPAddress, _port);
          }
          catch
          {
            return false;
          }

          if (_response != null)
          {
            if (_response.ErrorIndex != 0)
            {
              return false;
            }
            else
            {
              return true;
            }
          }
          else
          {
            return false;
          }
        }
        catch
        {
          return false;
        }
        finally
        {
          _mgr.Close();
        }
      }

With the upgraded dlls, a lot of these are missing, for example Manager.Timeout, Manager.Open, Manager.Response etc.
The examples provided are also related to a Master/Slave model with an agent.

Is it possible for you to provide some examples at least, with the current version,which has plain straight forward SNMP polling with the MIB, IP, port, Community and SNMP Version?

The reason I ask is so that we can get this into production with minimal code change, so that development/testing time can be saved.
WWSnmp
mithunbabu@gmail.com

From: 1155 Perimeter Center West, GA USA
Posts: 12
Member Since: 06/18/12
posted June 18, 2012 10:36 AM

Another example we had would be-

public string GetSNMPValue(string ipAddress, int port, MIBObjectEntity mib, string readCommunity, SNMPConstant.SNMPVersion snmpVersion)
    {
      ILogger _log = LoggerFactory.GetLogger(typeof(SNMPHelper).FullName);
      int _localPort = 0;

      string retVal = string.Empty;
      Manager mgr = new Manager();
      using (LoggerFactory.GetTracer(_log.ModuleName + "::_GetSNMPDataFromDart()"))
      {
        try
        {
          //TODO: need to make timeout a configuration setting
          mgr.Timeout = 3000;
          mgr.Open(_localPort);

          GetMessage get = new GetMessage { Community = readCommunity, Version = ToDartSNMPVersion(snmpVersion)};

          get.Variables.Add(new Variable(mib.OId));

          ResponseMessage response = null;
          try
          {
            response = mgr.GetResponse(get, ipAddress, port);
            IEnumerator iEnum = response.Variables.GetEnumerator();
            //TODO: not sure this is the best way to retrieve response data...
            while (iEnum.MoveNext())
            {
              string[] idValuePair = iEnum.Current.ToString().Split(',');
              retVal += idValuePair[1];
            }
          }
          catch (Exception exception)
          {
            _log.Error(exception);
          }

          if (response != null)
          {
            if (response.ErrorIndex != 0)
            {
              _log.Error(response.ErrorStatus.ToString());
            }
          }
          else
          {
            _log.Error("No response was sent.");
          }
        }
        catch (Exception exception)
        {
          _log.Error(exception);
        }
        finally
        {
          mgr.Close();
        }
        return retVal;
      }
     }
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 18, 2012 11:04 AM

The equivalent code would be:


public static bool GetStandardStatus(string _IPAddress, int _port, string _readCommunity, SnmpVersion _ver)
    {
      Manager _mgr = new Manager();
      ManagerSlave _mgrSlave = new ManagerSlave(_mgr);

      try
      {
        _mgrSlave.Socket.ReceiveTimeout = 3000;

        GetMessage _get = new GetMessage { Community = _readCommunity, Version = _ver };

        _get.Variables.Add(new Variable("1.3.6.1.2.1.1.3.0"));
        
        ResponseMessage _response;
        try
        {
          _response = _mgrSlave.GetResponse(_get, _IPAddress, _port);
        }
        catch
        {
          return false;
        }

        if (_response != null)
        {
          if (_response.ErrorIndex != 0)
          {
            return false;
          }
          else
          {
            return true;
          }
        }
        else
        {
          return false;
        }
      }
      catch
      {
        return false;
      }
      finally
      {
        _mgr.Close();
      }
    }
WWSnmp
mithunbabu@gmail.com

From: 1155 Perimeter Center West, GA USA
Posts: 12
Member Since: 06/18/12
posted June 19, 2012 11:50 AM

Thanks for the reply Tony.
Would you be able to help with this piece as well PLEASE?
The event ResponseMessageReceived, and the Async call GetResponseAsync seems to be missing in the new version.


public override bool Reboot(DriverEnums.ProtocolTypes _protocolType)
    {
      switch (_protocolType)
      {
        case DriverEnums.ProtocolTypes.SNMP_V2:
          if (CheckSNMPWriteParams())
          {
            Manager _mgr = new Manager();
            _mgr.ResponseMessageReceived += _mgr_ResponseMessageReceived;
            try
            {
              _mgr.Timeout = 3000;
              _mgr.Open(0);

              SetMessage _get = new SetMessage();
              _get.Community = _writeCommunity;
              _get.Version = SnmpVersion.Two;
              _get.Variables.Add(new Variable("1.3.6.1.4.1.3309.1.6.35.12.0", new Integer(1)));


              try
              {
                _mgr.GetResponseAsync(_get, _IPAddress, _port);
                return true;
              }
              catch
              {
                return false;
              }
            }
            finally
            {
              _mgr.Close();
            }
          }
          else
          {
            throw new Exception("SNMP V2 Params not set");
          }

        default:
          throw new NotSupportedException("Protocol not supported");
      }
    }
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 19, 2012 12:18 PM

I would take a look at the SnmpManager sample.
There is a doSetRequest method that asynchronously starts the snmpModel.SendSetRequest method and Marshalls the events back to the UI thread.
That sample should provide you with the information you need to update your code.

Regards,
Tony
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX