Get specific data from file...

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).
Post Reply
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

Get specific data from file...

Post by menno »

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 »

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

please help

Post by menno »

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 »

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 »

THANKS

this works great !!!
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You are welcome!
Post Reply