This custom sensor for IPCheck Server Monitor reads the available diskspace of a local drive and gives back a result.
This file (disksensorexe.dpr) serves as a sample for am EXE based custom sensor created using Delphi.
The sensor requires one parameter, which is the character of the drive to check (e.g. "c").
The source and the binaries can be found in the following subfolder of your IPCheck Server Monitor installation folder:
custom\sample\delphi\exe
Instructions:
program disksensorexe;
uses SysUtils;
var drive:string; driveid:byte; freespace:integer; m:string; code:integer;
begin try //read the parameter from the command line drive:=ansilowercase(paramstr(1)); //convert drive letter to id driveid:=ord(drive[1])-ord('a')+1; //read the free space in kb freespace:=DiskFree(driveid) div 1024; //check the free space and set result values if freespace<1 then begin code:=3; m:='Disk full'; end else if freespace<1024 then begin code:=1; m:='Only 1MB left'; end else begin code:=0; m:='Everything OK'; end; except //on exception return a error freespace:=0; code:=2; m:='Error reading free space.'; end; //send result to standard out writeln(inttostr(freespace)+':'+m); //set exit code halt(code)
end.