I think Osoba, Yinka SSI-TSSP-11 wrote:
>
>
> Hi Ernest,
>
> I'm writing an expert system to troubleshoot a software installation and
> what i'd like to do is retrieve information about the status of the
> installation from a log file as facts. Can you advise me on how to achieve
> this.
>
> Regards, Yinka Osoba.
Hi,
Well, the Jess-related part is easy enough; you probably want a Java
thread to be reading new messages from the install log and just
calling Rete.executeCommand("(assert (your-fact-here))") as
appropriate. You can use the 'sleeper rule' trick to keep the engine
running in the absence of applicable facts (see the 'pumps' example
for a version of this.)
The hard part is how to know when new messages show up at the end of
the file, essentially performing the work of UNIX's 'tail -f'
command. I've never tried to do this, so I don't know if there's a
portable way to do it.
The following trivial class (from another project of mine) reads from
an input stream and copies new data as it arrives to the end of a
named file. I use it with inputstreams that come from the stdout of an
execed process, and it works fine; but I'm not sure what would happen
if you fed it a FileInputStream. If it works, you could then replace
the file-writing part with a fact-asserting part, and you'd be golden.
----------------------------------------------------------------------
import java.io.*;
import java.util.*;
class ReaderThread extends Thread
{
InputStream m_is;
String m_fileName;
boolean m_verbose;
ReaderThread(InputStream is, String fileName, boolean verbose)
throws IOException
{
m_is = is;
m_fileName = fileName;
m_verbose = verbose;
setDaemon(true);
}
public void run()
{
if (m_is != null)
{
RandomAccessFile fos = null;
try
{
fos = new RandomAccessFile(m_fileName, "rw");
fos.seek(fos.length());
if (m_verbose)
{
String msg = "[[[ ------- Log opened at " + new Date()
+
"------- ]]]\n";
fos.write(msg.getBytes());
}
int i;
while (true)
{
if ((i = m_is.read()) != -1)
fos.write((char) i);
else
break;
}
}
catch (IOException ioe) { /* quietly exit */ }
finally
{
try
{
if (m_verbose)
{
String msg = "[[[ ------ Log closed at " + new
Date() +
"------ ]]]\n";
if (fos != null) fos.write(msg.getBytes());
}
if (fos != null) fos.close();
}
catch (IOException ioe) {}
}
}
}
}
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (510) 294-2154
Sandia National Labs FAX: (510) 294-2234
Org. 8920, MS 9214 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------