KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Method "File exists" Reply

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Wish list
View previous topic :: View next topic  
Author Message
sysadmber



Joined: 08 Dec 2015
Posts: 46

PostPosted: Mon Aug 22, 2016 11:56 pm    Post subject: Method "File exists" Reply Reply with quote

I added a couple of tests regarding file age.

Unfortuately there is no reply value. Could you please add it? I check if a file is not older that 12 Months. I see if the test is ok or not but i have to calculate the difference by hands which is not comfortable.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 11916
Location: USA

PostPosted: Tue Aug 23, 2016 5:10 am    Post subject: Reply with quote

What exactly reply value do you need?
HostMonitor can show file modification time (%FileTime% variable)

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
sysadmber



Joined: 08 Dec 2015
Posts: 46

PostPosted: Tue Aug 23, 2016 10:36 pm    Post subject: Reply with quote

I need the difference between the filedate and the configured value.

Example:

File Date is 01.08.2016. Today is 24.08.2016. The test goes bad if the file is older than 90 days.

Then the Reply should show 67 days left.
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Wed Aug 24, 2016 5:22 am    Post subject: Reply with quote

You may use Shell Script test for this task: http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell
Script may look like the following:
Code:
statusUnknown = "ScriptRes:Unknown:"
statusOk      = "ScriptRes:Ok:"
statusBad     = "ScriptRes:Bad:"

var objArgs = WScript.Arguments;

if (objArgs.length != 2) {
  WScript.StdOut.Write(statusUnknown + "Required 2 parameters: <file path> <max file age>");
  WScript.Quit;
}

var moddate;
var fname = objArgs(0);
var maxAge = parseInt(objArgs(1));

try {
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  var f = fso.GetFile(fname);
  moddate = f.DateLastModified;
} catch(e) {
  WScript.StdOut.Write(statusUnknown+ e.message+' ['+fname.replace(/\\\\/g,'\\')+']');
  WScript.Quit;
}

var dat = new Date;
var fileAge = parseInt((dat - moddate)/1000/60/60/24); //difference in days
var replyval = maxAge-fileAge;
if (fileAge>maxAge) {
  WScript.StdOut.Write(statusBad+replyval);
} else {
  WScript.StdOut.Write(statusOk+replyval);
}


Start cmd: cmd /c cscript /B /E:JScript %Script% %Params%

Script requires 2 parameters: <file path> <max file age>
Script returns reply with value <max file age> - <file age>

Shell Script params examples:
D:\logs\dataLog.log 90
"D:\old logs\dataLog.log" 180
Back to top
View user's profile Send private message Send e-mail Visit poster's website
KS-Soft



Joined: 03 Apr 2002
Posts: 11916
Location: USA

PostPosted: Wed Aug 24, 2016 8:45 am    Post subject: Reply with quote

Also we added 3 variables related to Folder/File Availability test method:
%FileAge_Min% - age of the file in minutes
%FileAge_Hour% - age of the file in hours
%FileAge_Day% - age of the file in days
Variables can be used as parameter of some actions, for Optional status processing, reports, etc

If you are using latest version of the software (10.30), you may download update at
www.ks-soft.net/download/hm1031.zip

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
sysadmber



Joined: 08 Dec 2015
Posts: 46

PostPosted: Wed Aug 24, 2016 11:36 pm    Post subject: Reply with quote

Thanks!

your script works very well. In Combination with "Tune up Reply Value" it is exactly what i wanted.
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Thu Aug 25, 2016 2:35 am    Post subject: Reply with quote

You are welcome.
Why do you need "Tune up Reply value" option for the script?
Have you tried using update for HostMonitor 10.30 with new variables?
Built-in test methods usually cunsume less resources.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sysadmber



Joined: 08 Dec 2015
Posts: 46

PostPosted: Thu Aug 25, 2016 5:51 am    Post subject: Reply with quote

The tuneup is only for adding a descriptive string to the suggestedReply variable

Yes i tested the new version and the variables. Thanks for your additions.

Your new variable %FileAge_Day% computes the difference between filedate and now, whereas your script computes the difference between now and the future day.
The latter is exactly what i wanted.

To use the new variables one must be able to compute with dates. Maybe something like that:

%Date%-(%FileDate%+%TestTime%) ???
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Thu Aug 25, 2016 6:51 am    Post subject: Reply with quote

With new variable you may use one of the following "Tune Up Reply value" expressions:
Days Left [90-%FileAge_Day%]
[90-%FileAge_Day%] days
[90-%FileAge_Day%]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sysadmber



Joined: 08 Dec 2015
Posts: 46

PostPosted: Thu Aug 25, 2016 11:07 pm    Post subject: Reply with quote

Perfect. I change the test to the new logic and everything works as expected.

Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Wish list All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index