Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. SNMP Get disk free space

SNMP Get disk free space

Scheduled Pinned Locked Moved Support
12 Posts 3 Posters 72.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y
    Y
    ytrasse
    wrote on last edited by
    #1

    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 😧
        blocksize = SNMPGetValue(transport, ".1.3.6.1.2.1.25.2.3.1.4.2");  // get Blocksize 😧
        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 ?

    1 Reply Last reply
    0
    • A
      A
      andrey--k
      wrote on last edited by
      #2

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


      hdd.xml

      1 Reply Last reply
      0
      • A
        A
        andrey--k
        wrote on last edited by
        #3

        I have get % of used space  😎

        See attach.


        hdd.xml

        1 Reply Last reply
        0
        • Y
          Y
          ytrasse
          wrote on last edited by
          #4

          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.


          server.xml

          1 Reply Last reply
          0
          • Y
            Y
            ytrasse
            wrote on last edited by
            #5

            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.


            storage-notok.xml

            1 Reply Last reply
            0
            • A
              A
              andrey--k
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • Y
                Y
                ytrasse
                wrote on last edited by
                #7

                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


                storage-ok.xml

                1 Reply Last reply
                0
                • A
                  A
                  andrey--k
                  wrote on last edited by
                  #8

                  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) ?

                  1 Reply Last reply
                  0
                  • Y
                    Y
                    ytrasse
                    wrote on last edited by
                    #9

                    Hello andrey--k

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

                    1 Reply Last reply
                    0
                    • A
                      A
                      andrey--k
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • B
                        B
                        Bing Wen
                        wrote on last edited by
                        #11

                        @ytrasse said in SNMP Get disk free space:

                        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.

                        1 Reply Last reply
                        0
                        • B
                          B
                          Bing Wen
                          wrote on last edited by
                          #12

                          @ytrasse said in SNMP Get disk free space:

                          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?

                          1 Reply Last reply
                          0

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better 💗

                          Register Login
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          Powered by NodeBB Contributors
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups