Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

1247

August 27th, 2013 17:00

ASL - string replacements

SAM / IP 7.x

Hi,

I receive traps from several devices whichs names follow slightly changing pattern.

In trap manager an asl script is included for the particular OID where I wanted to cut the names.

Actually I do it with substring and cut after 13th character what only meets a part of the devices sending traps.

The name convention patterns would be best explained with:

AABB1234567890_XX_YY

AABB1234567890_XXX_YY

AACC12345_XX_YY

AACC12345_XXX_YY

What they have in common is that I need the part before first "_".

As you can see I can't cut everything after n-th character nor could i count backwards, so substring wouldnt help me.

Is there a function I can use to match for "_" and cut this and everything after ?

Workaround would be to check for AABB or AACC and then cut after n-th character but I prefer a 1-liner.

Thanks

Christian

21 Posts

August 28th, 2013 04:00

If you have the hostname in a variable, e.g. HOSTNAME, you could try something like ...

HOSTNAME_PART1 = ""

...

PARSE_HOSTNAME {

  input = HOSTNAME;

  delim = "_";

  ..part1:word part2:word part3:word

} do {

  if (debug) {

  print("PARSE_HOSTNAME:".part1.'|'.part2.'|'.part3);

  }

   HOSTNAME_PART1=part1;

}

49 Posts

August 28th, 2013 14:00

Thank you Peter, that's exactly what I was looking for.

Usually doing all my SMARTS related stuff with PERL but afaik theres no way to start perl scripts from trap manager rules, so ASL gives me a pain from time to time.

Just inserted the above sniplet into my script and called rhe rule directly from START rule, now every device name is stripped at first occurence of "_". Perfect

21 Posts

August 28th, 2013 23:00

It is possible to run a perl script from ASL:

extScript = create( "ACT_PerlScript", "MY_SCRIPT" ) ? LOG, FAIL;
extScript->scriptName = "MyScript.pl";
extScriptParams = ELEMENTNAME;
extScript->trace = FALSE;
Results = list();
Results = extScript->run_ex( extScriptParams );
ExitStatus = Results[0];
Output = Results[1];

The script must be in the 'actions' directory

49 Posts

August 29th, 2013 12:00

That's good to know too. Thanks for this hint.

No Events found!

Top