SNMP Get disk free space

Started by ytrasse, March 03, 2014, 07:06:35 PM

Previous topic - Next topic

ytrasse

Hello

I want to get the free Disk space on a windows HDD.
But I can find in the host resource mib only "disk size = hrStorageSize" and "disk used space" = hrStorgeUsed.
So I decided to calculate disk free space from paramters above via transfromation script below.
(the DCI = $1 collects the disk size)

sub main()
{
  if ($node->isSNMP)
  {
   transport = CreateSNMPTransport($node);
    if (transport == null)
    {
       return -1;
    }
   
    diskused = SNMPGetValue(transport, ".1.3.6.1.2.1.25.2.3.1.6.2"); // get Disk used D:\
    blocksize = SNMPGetValue(transport, ".1.3.6.1.2.1.25.2.3.1.4.2");  // get Blocksize D:\
    if (diskused != null)
    {
        result = ($1 - diskused) ;       // Disk free = Disk size - Disk used
        result = result / ( 1024 * 1024 ) * blocksize / 1024 ; // transform to GByte
        return ( result );
       
    }
  }
}

But the script is not working. I always get the following error
"Cannot execute script: Incompatible operation"

Do you have any idea what is wrong in my script ?
Are there other possibliies to get the disk free and memory free space via SNMP ?

andrey--k

I am working on same.
Some experimental work in attached file (template export)

andrey--k

I have get % of used space  8)

See attach.

ytrasse

Hello

I already found the problem in my script.
It was no script problem, but a usage problem.
I tested it with the "Test" option, but I used it on the template instead of the applied server.
The transofrmation script itself seem's to be OK. It is working and returns the free disk space.

However I will also have a look to your hdd template andrey-k.

Attached there is my actual template.

ytrasse

Hello andrey--k

I tested your hdd-template. In general it seems to be ok. But there is no transforamtion script to display the values in GByte.
So I decided to merge your hdd-template with filter and instances with my working transformation script (see above).
But I had no real success, because it seems that {instance} is not allowed in transformation scripts.
e.g.
...
oid = ".1.3.6.1.2.1.25.2.3.1.5." . {instance};
disksize = SNMPGetValue(transport,  oid);  // get Disk size

I also created a template for getting the memory size/used/free/percent template similar to the disk templates.
My calculation of free memory here is also not working. (Other calculations are working)
transformation script:
sub main()
{
   memused = GetDCIValueByName($node,(".1.3.6.1.2.1.25.2.3.1.6.".$1));
   memsize = GetDCIValueByName($node,(".1.3.6.1.2.1.25.2.3.1.5.".$1));
   memfree = (memsize - memused) * 64 / 1024;
   return (memfree);
}

Attached there are my templates for Disk size/free/used/percent and Memory size/used/free/percent
It would be nice if somebody could check what is wrong with my templates.

andrey--k

#5
Transformation script to get disk space in Gib:

transport = CreateSNMPTransport($node);
if (transport == null)
{
return -1;
}
OidInstance = substr($dci->name,rindex($dci->name,".")+1);
oidBlockSize = ".1.3.6.1.2.1.25.2.3.1.4." . OidInstance;
blockSize = SNMPGetValue(transport, oidBlockSize);
blockSize = blockSize/1024;
GiB = round($1 * blockSize/(1024*1024));
return GiB;

Experiment shows, that main () {} is not needed.

ytrasse

Hello andrey-k

Transformation script is working perfect now.
Attached my modified storage template für disk an memory usage (size/used/free/percent) in Gbyte/MByte.
Maybe you can check it once more if everything is really working perfect and we can add this template to the standard
templates lib for other users.

One additional question.
Is there a way to modify also the DCI description in a kind that instead of Disk {instance} the storage description
from OID .1.3.6.1.2.1.25.2.3.1.3 is displayed ?  e.g. Disk C:\System



andrey--k

Am a little busy at the moment. I will begin work against memory/disks DCI implementation in week or two.
Please, can you test behavior of DCI when disk count changes (added or removed hard drive/cd drive/floppy) ?

ytrasse

Hello andrey--k

Filter and transfromation scripts are working on machines with several disk partitions, ond machines with and without DVD-drive.

andrey--k

At the moment I provide some tests:
1 Disk usage/free gives incorrect values on empty/full disks.
2 Memory usage do not gathered 3-5 pools after hard-disk-volume add/remove. later all in order.

But also good news: system normaly works when disk manipulation was done.

Bing Wen

Quote from: ytrasse on March 04, 2014, 01:09:28 PM
Hello

I already found the problem in my script.
It was no script problem, but a usage problem.
I tested it with the "Test" option, but I used it on the template instead of the applied server.
The transofrmation script itself seem's to be OK. It is working and returns the free disk space.

However I will also have a look to your hdd template andrey-k.

Attached there is my actual template.

Hi ytrasse,

I tried to add a new DCI based on your attached file. But i could only get 0 for the last value.

Bing Wen

Quote from: ytrasse on March 13, 2014, 03:40:35 PM
Hello andrey--k

I tested your hdd-template. In general it seems to be ok. But there is no transforamtion script to display the values in GByte.
So I decided to merge your hdd-template with filter and instances with my working transformation script (see above).
But I had no real success, because it seems that {instance} is not allowed in transformation scripts.
e.g.
...
oid = ".1.3.6.1.2.1.25.2.3.1.5." . {instance};
disksize = SNMPGetValue(transport,  oid);  // get Disk size

I also created a template for getting the memory size/used/free/percent template similar to the disk templates.
My calculation of free memory here is also not working. (Other calculations are working)
transformation script:
sub main()
{
   memused = GetDCIValueByName($node,(".1.3.6.1.2.1.25.2.3.1.6.".$1));
   memsize = GetDCIValueByName($node,(".1.3.6.1.2.1.25.2.3.1.5.".$1));
   memfree = (memsize - memused) * 64 / 1024;
   return (memfree);
}

Attached there are my templates for Disk size/free/used/percent and Memory size/used/free/percent
It would be nice if somebody could check what is wrong with my templates.

Hi ytrasse,
I have tried your transformation script and it's not working. Is there any updates?