DCI filter script - how to ignore some filesystems when using {instance} ?

Started by hkusulja, May 07, 2014, 08:29:35 PM

Previous topic - Next topic

hkusulja

Hi,
I have configured Template with DCI: NetXMS Agent, to monitor FileSystem.UsedPerc({instance})

This will create on each node monitoring of Used disk space on file system for every single drive it founds.

However I need to write some script / somewhere to ignore some filesystems, for example, on Windows this is (if instance name contains A: or B: ) because I do not want to monitor floppy disks.

Any suggestions, where to write this script / rule and what is syntax ?

Thank you

Victor Kirhenshtein

Hi!

You can create filtering script for instance discovery which will attempt to get total space for file system and only return true if data was read successfully and size is non-zero. It could be something like this:


value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")");
return (value != null) && (value > 0);


Best regards,
Victor

sharpspro

That script worked great. Is there a way to add to it?

I would like for the drives that do not have drive letters to NOT show up e.g. "Percentage of free space on file system \\?\Volume{xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx}\" ----instead I only want it to show valid drives e.g. "Percentage of free space on file system C:\"

I will continue to search on this but any help is appreciated.

multix

if (rindex($1,":")>0)   // this is for your case.
{
// if(length($1)>3) return false;    // in some cases, you can link a disc drive to directory. uncomment this line if you don't want to see them.
if (rindex($1,"A:")>0) return false;  // in my case, i have virtual pcs, and some of them have floppy disk drives, i don't want to see them.
value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")");
return (value != null) && (value > 0);
//return %(true, $1);
}
return false;


sharpspro

The issue I see with this is when a CD disk does not report its value as ERROR and starts reporting the value as "0". An example of this would be when a CD/DVD is put into the drive and the reported value changes from ERROR to 0 (zero) space available and the threshold alert will be sent.


My question is, is there a way to exclude CD/DVD drives completely with this filter? Or is there another work around to get this accomplished?

Below is how I have the scrpit currently:
if (rindex($1,":")>0)
{
// if(length($1)>3) return false;
if (rindex($1,"A:")>0) return false;
value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")");
return (value != null) && (value > 0);
//return %(true, $1);
}
return false;

Victor Kirhenshtein

Hi,

in version 2.0-M3 I've added new parameter FileSystem.Type, so with agent version 2.0-M3 you can filter out CDs as following:


if (rindex($1,":")>0)
{
   type = AgentReadParameter($node, "FileSystem.Type(" . $1 . ")");
   // exclude CDs:
   return (value != null) && (value != "CDFS"); 
   // if only NTFS systems are of interest (usual situation):
   // return value == "NTFS";
}
return false;


Best regards,
Victor

sharpspro

Hi Victor,

Thanks for the reply! When will that version 2.0-M3 be available?

Thanks!

Victor Kirhenshtein

Most likely next week, or week after in worst case.

Best regards,
Victor

sharpspro

Guys,

I'm looking to create a script that will only show drives within a certain size range. For example only show drives that are between 500Gb and 1,000GB or 1,000GB and 1,500GB.

The reason being is that i want to setup thresholds differently on drives. Smaller drives i would like to have a higher percentage free than huge drives. The bigger the drive gets the lower i want the percentage free to alert on the threshold.

Alex Kirhenshtein

if ($1 =~ "[:/]") {
  value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")")
  return (value > 5*1024*1024*1024 && value < 1*1024*1024*1024*1024);
}
return false;


Quote from: sharpspro on April 21, 2015, 09:40:10 PM
Guys,

I'm looking to create a script that will only show drives within a certain size range. For example only show drives that are between 500Gb and 1,000GB or 1,000TB and 1,500GB.

The reason being is that i want to setup thresholds differently on drives. Smaller drives i would like to have a higher percentage free than huge drives. The bigger the drive gets the lower i want the percentage free to alert on the threshold.

sharpspro

I tried your suggestion and it did not work for me. Currently I'm using a filter script to ignore CD/DVD drives that report as errors when there is no disk inserted as well as system partitions with no drive letter. I got the script from this post please review below.

CURRENT SCRIPT
if (rindex($1,":")>0)
{
// if(length($1)>3) return false;
if (rindex($1,"A:")>0) return false;
value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")");
return (value != null) && (value > 0);
//return %(true, $1);
}
return false;


SO for the DCI I created I removed the current script I use and I tried your suggestion and it located all drives and didn't filter anything.

NEW SCRIPT
if ($1 =~ "[:/]") {
  value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")")
  return (value > 5*1024*1024*1024 && value < 1*1024*1024*1024*1024);
}
return false;


For the values you suggested (5*1024*1024*1024) is for 5GB I asume and (1*1024*1024*1024*1024) is for 1TB. If I understand this right, if I wanted to filter drives that are 500GB to 1000GB I would use (value > 512*1024*1024*1024 && value < 1*1024*1024*1024*1024) Not sure on this and hope its not a stupid question.

sharpspro

Any Ideas? I'm running Version 2.0-M1 on Windows Server 2008r2. Do I need to upgrade to M2 for the script you provided to work? I'm waiting for M3 to be tested more before I upgrade to that version.

Victor Kirhenshtein

This script:


if ($1 =~ "[:/]") {
  value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")")
  return (value > 5*1024*1024*1024 && value < 1*1024*1024*1024*1024);
}
return false;


has few typos - match operation is ~= and semicolon is missing in line 2. It should be


if ($1 ~= "[:/]") {
  value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")");
  return (value > 5*1024*1024*1024 && value < 1*1024*1024*1024*1024);
}
return false;


Best regards,
Victor

sharpspro

Some reason that script is not working. I included screen shots maybe I have something wrong.

When I change the scrpit to the one I used prior and it locates all the drives. That script is below.

if (rindex($1,":")>0)
{
// if(length($1)>3) return false;
if (rindex($1,"A:")>0) return false;
value = AgentReadParameter($node, "FileSystem.Total(" . $1 . ")");
return (value != null) && (value > 0);
//return %(true, $1);
}
return false;