Is there a way to automatically download the logfile 'kmsgr_output'?

I run a Windows script towards the end of the work day, to tell me how many times the computers have connected to the K1000.
I have to login on to http://k1000/system, then go to troubleshooting tools, and download the whole compressed logs, then pull out the 1 logfile I need. I want to automate that.

Or, even better, is it possible to determine how many times the computers have connected using an SQL query?
Here is the Windows JS file I made, maybe there is a way to construct a similar SQL query.

// FindAndCountHostnames.js
// Needs kmsgr_output from kbox_logs.tgz at
// kbox\kboxwww\logs\kmsgr_output in same folder as script.
// Results printed to results.txt in same folder as script.

var objFso = new ActiveXObject("Scripting.FileSystemObject");
// FSO OpenTextFile constants
var ForReading = 1;
var ForWriting = 2;
var ForAppending = 8;

var idxComputers = new ActiveXObject("Scripting.Dictionary");
var TextCompare = 1;
idxComputers.CompareMode = TextCompare;

// Hostname regex stored in first match.
var reHosts = new RegExp("host\=(.*)\&nictype", "i");
reHosts.compile("host\=(.*)\&nictype", "i");

// kmsgr_output input file
var strInFile = "kmsgr_output";

if (!objFso.FileExists(strInFile)){
  WScript.Echo(strInFile + " not found.");
  WScript.Quit(1);
}

try{
  var objInFile = objFso.OpenTextFile(strInFile, ForReading);
}
catch(e){
  WScript.Echo("Problem opening " + strInFile);
  WScript.Quit(2);
}

var strCurrLine, arrMatches;

while (!objInFile.atEndOfStream){
  strCurrLine = objInFile.ReadLine();
  arrMatches = reHosts.exec(strCurrLine);

  if (arrMatches != null){
    // Store count of hostnames.
    if (idxComputers.Exists(RegExp.$1)){
    idxComputers.Item(RegExp.$1) = idxComputers.Item(RegExp.$1) + 1;
  }
    else{
    idxComputers.Add(RegExp.$1.toUpperCase(), 1);
    }
  }
}
objInFile.Close();

if (idxComputers.Count == 0){
  WScript.Echo("No computers found.");
  WScript.Quit(3);
}

var arrKeys = (idxComputers.Keys().toArray()).sort();

var strOutFile = "results.txt";

try{
  // Write results to file.
  var objOutFile = objFso.OpenTextFile(strOutFile, ForWriting, true);
  objOutFile.WriteLine("Computername" + "\t" + "NumberOfConnects");
 
  for (var i = 0; i < arrKeys.length; i++){
    objOutFile.WriteLine(arrKeys[i] + "\t" + idxComputers.Item(arrKeys[i]));
  }
}
catch(f){
  WScript.Echo("Problem creating " + strOutFile);
  WScript.Quit(4);
}
objOutFile.Close();

WScript.Echo("Finished");



0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

2

The logs tarball is definitely not a good way to go because of the challenges listed.  If you contact support you can get a patch that will give you read access to the log directory at \\k1000\logs1 file share instead.  We use this for troubleshooting but you could use it to look at some logs.  Note that you have to reapply it after a reboot.

However, the answer might be a lot easier then you think. Asset History tracks all the disconnect/connects for that last 24 hours. 5.4 tracks them efficiently but the query is much different then 5.3. The kbox purges the ASSET_HISTORY events like these at 2359h every night but you could schedule a report to run just prior to that:

Here's the query:

 select 
M.NAME "Machine",
M.IP,
count(*) "Connects"
from
ASSET_HISTORY H
join ASSET A on A.ID=H.ASSET_ID
join MACHINE M on M.ID=A.MAPPED_ID
where
CHANGE_TYPE = 'Connection'
and date(H.TIME) = curdate()
group by ASSET_ID
having count(*) >= 10 -- optional
order by 3 desc

-----------

You could also parse the file. This is how I might do it but not sure how on windows:

 cat kmsgr_output | grep -E 'Connect.*agentInfo' | awk '{print $8}' | sort | uniq -c | sort

I've chosen to group by KUID but you could do something else. The output looks like this:

  31 (609E5A15-DAD6-4CE2-9B22-7C55D32A3FCA);
  31 (7C2C64A8-BA9F-4BCC-A5DA-9788422EEE25);
  52 (392515D9-92DC-464A-990C-DC6609190419);
Answered 01/25/2013 by: GillySpy
Seventh Degree Black Belt

  • The SQL query worked great! I will use that in a end-of-day report. Thanks for the 1 liner too.
Please log in to comment
Answer this question or Comment on this question for clarity

Share