Solved

Getting the data from SNMP agent

Posted on 2004-10-11
10
855 Views
Last Modified: 2016-10-28
Hi All,
I have to write code to get the data from SNMP agents installed on win2k server machines. Has anyone written a code for this, please share it. Or if there are available free APIs which i can use to create SNMP Manager to get the Data like CPU usage, Memory Usage, Disk Usage from remote machines, please share.

Thanks
Alok
0
Comment
Question by:alokgupt
  • 5
10 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 126 total points
ID: 12280299
Check out the samples at http://www.winsnmp.com/samples/c/index.htm

>>to get the Data like CPU usage, Memory Usage, Disk Usage

That's not part of SNMP, you'd use the PDH library to do that. Check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/accessing_counters_on_remote_machines.asp ("Accessing Counters on Remote Machines"), http://support.microsoft.com/default.aspx?scid=kb;en-us;287157 ("How To Determine Physical Memory on a Remote Machine") and http://support.microsoft.com/default.aspx?scid=kb;en-us;287157 ("INFO: PDH Sample Code to Enumerate Performance Counters and Instances")
0
 

Author Comment

by:alokgupt
ID: 12283979
Thanks JKR,
 But there are several tools available in the market who use SNMP to get Machine data (CPU/Memory/Hard Disk) across the network. One such tool is " Paessler RouterTraffic Grapher". So i think there should be some way to get OIDs for these parameters (CPU/Memory/Hard Disk). Does Microsoft provide OIDs for these parameters (CPU/Memory/Hard Disk)?????


Thanks
--Alok
0
 

Author Comment

by:alokgupt
ID: 12285913
The following code is a part of service which is running with an interval of 5 mins (300000 ms)
//////////////////////////////////////////////////////////////////////////////////////////////////////////
LPSNMP_MGR_SESSION lpSNMPSession;
LPSTR lpAgentAddress = "172.17.32.144";
LPSTR lpAgentCommunity = "public";
INT nTimeOut = 30000;
INT nRetries = 100;
lpSNMPSession = SnmpMgrOpen(lpAgentAddress,lpAgentCommunity,nTimeOut,nRetries);
if (lpSNMPSession != NULL)
{
      SNMPAPI snmpapiRetVal;
      SnmpVarBindList* variableBindings = NULL;
      AsnInteger* errorStatus = SNMP_ERRORSTATUS_NOERROR;
      AsnInteger* errorIndex;
/* I don't know what SnmpMgrRequest will return so i tried this part */
      snmpapiRetVal = SnmpMgrRequest(lpSNMPSession,SNMP_PDU_GET,variableBindings,errorStatus,errorIndex);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////

Now here SnmpMgrRequest is returning an error "Request Timed-out." or SNMP_MGMTAPI_TIMEOUT. Can anyone let me know what can be the reason. And how should i call SnmpMgrRequest so that i can some data from the Remote agent.

--Thanks
Alok
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:alokgupt
ID: 12305338
I have one more query: While i am calling

HSNMP_ENTITY pSrcEntity ;
HSNMP_ENTITY pDstEntity ;
HSNMP_CONTEXT pContext ;
HSNMP_PDU PDU ;
SnmpRecvMsg(hSession,&pSrcEntity,&pDstEntity,&pContext,&PDU);

it returns SNMPAPI_SUCCESS but PDU is empty for OID "1,3,6,1,2,1,1,3,0". This OID is correct as i have checked using one of the third party tool.

Can anyone let me know what can be wrong with it.

Thanks
Alok

0
 

Author Comment

by:alokgupt
ID: 12336446
Does anyone know OID for Memory Usage and Hard Disk Drive available space?


Thanks
Alok
0
 

Author Comment

by:alokgupt
ID: 12441966
Ne updates???
0
 
LVL 1

Assisted Solution

by:monu85
monu85 earned 125 total points
ID: 12442546
For Memory you can try these OIds
.1.3.6.1.2.1.25.2.1.2
.1.3.6.1.2.1.25.2.1.3
.1.3.6.1.2.1.25.2.1.8
.1.3.6.1.2.1.25.2.2
.1.3.6.1.2.1.25.2.3.1.5
.1.3.6.1.2.1.25.2.3.1.6

And For Hard Disk check you can try these
.1.3.6.1.2.1.25.3.1.6
.1.3.6.1.2.1.25.3.1.20
.1.3.6.1.2.1.25.3.1.21
.1.3.6.1.2.1.25.3.6.1.1
.1.3.6.1.2.1.25.3.6.1.2
.1.3.6.1.2.1.25.3.6.1.3
.1.3.6.1.2.1.25.3.6.1.4

Hope atleast one of them will work.

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c++ getting the first 10 characters of a char* string 11 94
thread-safe code in c++ 2 102
How to convert MFC::CString to UTF8 wchar_t* 10 211
Problem with SqlConnection 4 169
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question