Start a Conversation

Unsolved

This post is more than 5 years old

6806

December 29th, 2009 06:00

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

December 29th, 2009 11:00

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

37 Posts

February 16th, 2010 00:00

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=

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

36 Posts

February 16th, 2010 05:00

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

February 16th, 2010 08:00

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

37 Posts

February 16th, 2010 20:00

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

37 Posts

February 16th, 2010 22:00

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

May 6th, 2010 04:00

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

52 Posts

May 27th, 2010 05:00

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

June 7th, 2010 06:00

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:
// /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

22 Posts

December 3rd, 2015 07:00

These posts have really helped but I still have an issue reading in data if anyone is able to assist.

The last post by Isabelle works for me but as mentioned is not the best solution for larger datasets in SMARTS, the use of GA_StringDictionary and the example by Arun has the following errors when executed like this:-

/apps/InCharge/SAM/smarts/bin/sm_adapter /apps/InCharge/SAM/smarts/local/rules/icoi-trapd/main_script.asl

[December 3, 2015 3:42:24 PM GMT +628ms] t@2107602720 adapter
ASL-E-ERROR_RULE_INIT-While initializing rule set
ASL-ERROR_FILE_PARSE-While parsing rules in file '/apps/InCharge/SAM/smarts/local/rules/icoi-trapd/main_script.asl'
ASL-ERROR_YACC_ERROR-Parsing error: 'syntax error at line 29, next token is '''

[December 3, 2015 3:42:24 PM GMT +646ms] t@2107602720 adapter
SVIF-N-SHUTDOWN-Shutting down...

line 29 in the main script  is the last line [stop();], my code is a cut & paste of Arun's example, the readfile.asl I am suing is also a cut & paste and just 2 lines long, i.e.

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

stringObj->insert(a,"");

Any help is appreciated.

Mark.

No Events found!

Top