All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
menno
Posts: 158 Joined: Fri May 21, 2010 1:27 am
Post
by menno » Sun Aug 17, 2014 11:56 pm
hi team !
We collect server temperature with software that puts all data in 1 TXT file
example:
Code: Select all
[temp server 1]
40.5
[temp server 2]
41.2
[temp server 3]
45.2
nothing more is in this file !
Is it possible to make a test that filter only the value of server 2
We want to make a test that filter out (in this example) the value : 41.2
In this case we can me a specific test for a customer.
is this possible ???
many thanks in advance
menno
KS-Soft Europe
Posts: 2832 Joined: Tue May 16, 2006 4:41 am
Contact:
Post
by KS-Soft Europe » Mon Aug 18, 2014 7:21 am
You need to use Shell Script test with custom made script.
E.g. Custom made JavaScript may look like the following:
Code: Select all
statusUnknown = "ScriptRes:Unknown:"
statusOk = "ScriptRes:Ok:"
statusBad = "ScriptRes:Bad:"
function getFile(fname,findstr) {
try {
var oFS = new ActiveXObject('Scripting.FileSystemObject');
var oFile = oFS.OpenTextFile(fname);
var str = ''
while (!oFile.AtEndOfStream) {
str = oFile.ReadLine();
if (str.indexOf(findstr)>-1) {
str = oFile.ReadLine();
oFile.Close();
return str;
}
}
oFile.Close();
} catch(e) {
WScript.StdOut.Write(statusUnknown + e.message+' ['+fname.replace(/\\\\/g,'\\')+']');
WScript.Quit;
return e.message;
}
WScript.StdOut.Write(statusUnknown + 'Parameter '+findstr+' not found');
WScript.Quit;
}
objArgs = WScript.Arguments;
if (objArgs.length!=3) {
WScript.StdOut.Write(statusUnknown + 'Required 3 parameters: <path to the file> <param line> <threshold value>');
WScript.Quit;
}
fc1 = getFile(objArgs(0),objArgs(1));
var val1 = parseFloat(fc1);
var val2 = parseFloat(objArgs(2));
if (val1>val2) {
WScript.StdOut.Write(statusBad+fc1);
} else {
WScript.StdOut.Write(statusOk+fc1);
}
Start cmd:
cmd /c cscript /B /E:JScript %Script% %Params%
Script requires 3 parameters: <path to the file> <param line> <threshold value>
e.g.:
"D:\tempdata\test.txt" "[temp server 2]" 40
Please check for details at:
http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
menno
Posts: 158 Joined: Fri May 21, 2010 1:27 am
Post
by menno » Wed Feb 18, 2015 1:57 pm
hi there
thanks for all the help in the last example
but...
the makers of the software changed a small piece in their software
the servers temperature changes to 2 values
so ..
my file looks like this :
[temp server 1]
111.2
44
[temp server 2]
105.8
41
[temp server 3]
113.0
45
so from now on i need the SECOND line off my text file
i played with the above script but did NOT find how to extract the SECOND line
can you please help me ??
we need this to monitor our servers temperature
many many thanks in advance
menno
KS-Soft Europe
Posts: 2832 Joined: Tue May 16, 2006 4:41 am
Contact:
Post
by KS-Soft Europe » Wed Feb 18, 2015 2:12 pm
You need just to insert the following line:
oFile.ReadLine();
right before
str = oFile.ReadLine();
New script should look like the following:
Code: Select all
statusUnknown = "ScriptRes:Unknown:"
statusOk = "ScriptRes:Ok:"
statusBad = "ScriptRes:Bad:"
function getFile(fname,findstr) {
try {
var oFS = new ActiveXObject('Scripting.FileSystemObject');
var oFile = oFS.OpenTextFile(fname);
var str = ''
while (!oFile.AtEndOfStream) {
str = oFile.ReadLine();
if (str.indexOf(findstr)>-1) {
oFile.ReadLine();
str = oFile.ReadLine();
oFile.Close();
return str;
}
}
oFile.Close();
} catch(e) {
WScript.StdOut.Write(statusUnknown + e.message+' ['+fname.replace(/\\\\/g,'\\')+']');
WScript.Quit;
return e.message;
}
WScript.StdOut.Write(statusUnknown + 'Parameter '+findstr+' not found');
WScript.Quit;
}
objArgs = WScript.Arguments;
if (objArgs.length!=3) {
WScript.StdOut.Write(statusUnknown + 'Required 3 parameters: <path to the file> <param line> <threshold value>');
WScript.Quit;
}
fc1 = getFile(objArgs(0),objArgs(1));
var val1 = parseFloat(fc1);
var val2 = parseFloat(objArgs(2));
if (val1>val2) {
WScript.StdOut.Write(statusBad+fc1);
} else {
WScript.StdOut.Write(statusOk+fc1);
}
menno
Posts: 158 Joined: Fri May 21, 2010 1:27 am
Post
by menno » Wed Feb 18, 2015 2:25 pm
THANKS
this works great !!!