Highlighted
gopal_emc
1 Copper

How to read flat file from ASL?

Hi,

Is there any way by which the flat files can be read from the ASL files?
I need to read the data realtime from the flat file and need to do the processing based on the contents.

I remember that a driver can be written for the same however I am not recollecting the complete procedure.

Please could any of you advice on this?

Thanks in advance.

With Warm Regards,
Gopal

0 Kudos
10 Replies
FredericMeunier
3 Argentium

Re: How to read flat file from ASL?

Hi Gopal,

please give use more information. To read from a file in an ASL script, you can use sm_adapter (--file or --tail depending of your need), but maybe you want to do this in an existing ASL script (discovery or so ...) ?

--Fred

== Monitor your Smarts environment using APG ReportPack for Smarts health ==
Frederic Meunier
Solutions Watch4Net Inc
APG & Smarts InCharge integration
http://www.watch4net.com

ArunDeva
2 Bronze

Re: How to read flat file from ASL?

Hi Fred,

How can we read a file from an ASL file, other than using --file option.

Because, to use the --file option, the asl file has to run as follows

sm_adapter --file=<file to be read> <asl file>

But consider a scenario, that I need to handle a trap which uses an ASL file to process it. This ASL has to read another flat file to fetch some data to process the trap. Could you please advice how can we call or how can we fetch the data from another flat file from the ASL file?

Thanks

Arun

0 Kudos
Berkay1
2 Bronze

Re: How to read flat file from ASL?

Arun,

Unfortunately, this is not a scenario supported in Smarts. If you have to use file contents in trap processing, you need to load the file contents into the memory first so that you can access it while processing the traps. EMC suggests (used to?) using GA_StringDictionary class to store this type of data.

This is also true if you want to process data from any external source such as a database, etc. If loading the data into GA_StringDictionary workaround is not an option, you're left with developing an external adapter using perl/java API.


Regards,
Berkay Mollamustafaoglu
http://www.ifountain.com
Ph: +1 (571) 766-6292
mberkay on yahoo, google and skype

0 Kudos
FredericMeunier
3 Argentium

Re: How to read flat file from ASL?

Hi,

I second Berkay. He is right. And in general, and IMHO, it is better to have a kind of a cache (GA_...) to process traps and not having to parse a file each time a trap does enter (what if a trap storm ...). The GA_StringDictionnary is still available for update anytime.

--Fred

0 Kudos
ArunDeva
2 Bronze

Re: How to read flat file from ASL?

Hi Berkary/Fred,

Thanks a lot for this information.

But could you please advice, how this asl files are fetching the details from the conf files?

For eg: ic-topomanager.asl file in AM Domain is fetching details from other conf files, discovery-init.asl file is fetchign details from other external files. But being honest, I didnt understand how they work as I dont have much experience in writing ASL codes.

I am sorry, if I am asking stupid questions.

-Arun

0 Kudos
ArunDeva
2 Bronze

Re: How to read flat file from ASL?

Hurray.....

Hi Berkay/Fred,

It really worked with GA_StringDictionary class.

Hi Gopal,

So by this way, we can fetch the data from a flat file.

*********************************************************************************

//Main ASL file.

fe = create("GA_FileFE","Sample-Read-File");

fe->fileName="/opt/InCharge7/IP/smarts/local/logs/test.txt";

driver = create("GA_Driver","Sample-Read-Driver");

rule = create("GA_RuleSet", "Sample-Read-RS");

rule->fileName = "read.asl";

driver->waitForCompletion = TRUE;

driver->ReadsInputFrom = fe;

driver->ReadsRulesFrom = rule;

driver->start();

stringObj = object("GA_StringDictionary","Sample-Read-Dictionary");

values = list();

values = stringObj->keys;

print("got the values ".values);

stringObj->clear();

stop();

//The rule set ASL file, read.asl

stringObj = create("GA_StringDictionary","Sample-Read-Dictionary");

stringObj->insert(a,"");

//External file which is the input, test.txt

first variable

second variable

thrid variable

*********************************************************************************

Berkay/Fred,

Any comments, or advice are most welcome.

Thanks

Arun

0 Kudos
praveenbajaj
1 Copper

Re: How to read flat file from ASL?

How can we do a wild search from String Dictionary?

For example we have "abcdef" as key in the string dictionary . I want to do a  search the dictionary using "cd" and get the value.

Is there any other way to do apart from using GA_StringDictionary

0 Kudos
bkuhhirte
2 Iron

Re: How to read flat file from ASL?

Gopal,

     The GA_StringDictionary is a simple hash table (key value pair) and not really suitable for wildcard searches by itself.  That said, the "keys" attribute is a list of the keys.  You could check each key using a glob pattern or "stringify" the set of keys and glob against that to see if the key exists.  The latter would be quicker, but probably won't help you get the *specific* key that matches without going through the list.

     Simplistically (and probably not great performance) it would look like this:

     string pattern = "*cd*";

     value = "";

     foreach key (gaStringObj->keys) {

          if (glob(pattern, key)) {

               value = gaStringObj->find(key);

               break;

          }

     }

--Bill

0 Kudos

Re: How to read flat file from ASL?

Hello.

Well, I just thought I could also supply an example of how to read a file without using the GA_StringDictionnary class. I have used similar scripts more than once with my applications, although I commonly use it to read files located in remote SMARTS domains (if that is you case, please contact me for another example).

Below, you can find an example of file reading and parsing using two ASL scripts. The first one "Test.asl" calls the "FileReader.asl" script to get the contents of the file "test.csv" and parse its results.

Cordially,

Isabelle C. de Andrade

Telecom Engineer - Neppo TI

// Test.asl: main asl script
START {
.. eol
}
do {
// Starts a GA_Driver
driver=create("GA_Driver", "File-Reader-Driver".thread()) ? FAIL;
driver->waitForCompletion=TRUE;

// ASL script path which is referrenced to SMARTS rules installation folder:
// <SMARTS>/local/rules/ReadFile.asl
ruleObj=create("GA_RuleSet", "File-Reader-RS".thread()) ? FAIL;
ruleObj->fileName = "ReadFile.asl";
driver->ReadsRulesFrom=ruleObj;

// Get file full path
sysObj = object("SM_System", "SM-System");
HOMEDIR = sysObj->homedir;
filename = HOMEDIR."local/logs/test.csv";

// Create driver
driver->ReadsInputFrom=create("GA_FileFE", "File-Reader-FE".thread()) ? FAIL;
driver->ReadsInputFrom->fileName = filename;

// Pass parameters to ASL script
// example: params->insert("PassedParamName", "PassedParamValue");
params =driver->getMyParameters();
params->clear();
params->insert("Output", "");

// Run script
params->getDriverResults=TRUE;
driver->startWithParameters(params);

// Get results
FileContents = params->find("Output");
// Parse results
PARSE(FileContents);
}

PARSE(value) {
input = value;
delim = ";";
c1: word
c2: word
"\n"
line: {.. eol}
}
do {
// Process each line
print("This is the first column: ".c1);

// Continue to parse results until end of file has been reached.
// You can use a stop character to determine the end of file if
// the following test doesn't work.
if (sizeOf(line) > 0) {
PARSE(line);
}
}

// ReadFile.asl: Simple asl script responsible for reading the complete file.
default Output = "";
START {
line: {.. eol}
}
do {
Output = Output.line;
}

// test.csv: file example
this;is
a;test
0 Kudos