Alarms
-
-
If I understand you need correctly, you need script which will convert numeric codes into strings, right? Then you can do the following:
Create script in script library, with some name, let's say "convert" (here I assume that you need to convert event's parameter %2 into text - otherwise change index in parameters[] accordingly):
switch($event->parameters[2]) { case 1: return "test"; case 2: return "test2"; // and so on... } return "unknown"; // default valueand then use it in a message like %[convert]
Best regards,
Victor -
hi victor,
this is what i was looking for.when i thought about the solution myself i have remembered that you helped me once with the $node parameters but i would have never guessed the $event parameter.
sorry to be a nag but this is another good example for why the documentation has to be updated.
thank u and best Regards,
Lindeamon -
hi victor,
i have another question on the subject.
i receive an alarm with 3 parameters where all of them are numbers that i want to convert to text.
as a test for the 1st one i have used your script and it worked fine so now i want to upgrade it.
i want to write 2 sub's where the 1st one will receive event parameter 1 (and this i know how to do with the script you gave me) and the 2nd one will check parameters 2 and 3.
i have tried it myself but i do not know the correct syntax and parameter placing to subroutines.
i want the above in 1 script file.Best Regards,
lindeamon -
Hi!
Currently it is not possible - server always calls main() subroutine when expanding %[] macro. I can add an option to specify parameters and/or entry points to these scripts - in 1.1.8 or 1.1.9, depending on how fast I will fix other things from to-do list.
Best regards,
Victor -
hi victor,
thank you very much.this is not urgent but it would make things more tidy.
how do i transfer parameters to a sub function ?
my last 2 parameters of the event can use the same function so i can use the same script but as you figured out the $event-parameters will be differnt and will have to be transfered as variables,how do i do that ?Best Regards,
Lindeamon -
Parameters can be passed to subroutines like that:
sub main() { f(1, 2); f(3, 4); } sub f(p1, p2) { println "parameter 1 is " . p1; println "parameter 2 is " . p2; }If you have multiple parameters which needs to be converted using same function, you can create separate script in the library containing this function, and call it from different small scripts. For example, create script called "convert" with function "convert":
convert(p) { // do conversion here return converted_value; }then create scripts like that for each parameter:
convert_p1:
use convert; return convert($event->parameters[1]);convert_p2:
use convert; return convert($event->parameters[2]);and so on.
Best regards,
Victor -
-
hi victor,
no luck.
i have created 2 scripts:- the main script for converting called "CISCO_Config_Event_Config" and it's syntax is:
  sub main(e)
  {
  switch(e)
  {
  case 3: return "running";
  case 4: return "startup";
  }
  } - the event #3 param script called "CISCO_Config_Event_Source" and it's syntax is:
  use CISCO_Config_Event_Config;
  return CISCO_Config_Event_Config($event->parameters[3]);
in the event i have configured like this:
%[CISCO_Config_Event_Source]and nothing works.where is my problem ?
Best Regards,
Lindeamon - the main script for converting called "CISCO_Config_Event_Config" and it's syntax is:
-
-
You should not have function main() in library script. Try to change it like this:
sub CISCO_Config_Event_Config(e) { switch(e) { case 3: return "running"; case 4: return "startup"; } }It is strange that server crashes. I'll try to reproduce it myself.
Best regards,
Victor -
hi victor,
it worked.
now, i do not understand why i had to do it like this,can you break down the syntax for me ?
for exm., i understand that "use XXXXX" will use the XXXXX script and the "return XXXX" is transferring what ever is in the () to the script but what i do not understand is why i had to do the last change you recommended ?
when i do this configuration the used script become the name of the function ?Best Regards,
Lindeamon -
Hi!
There are some confusion caused primarily by giving script itself and a function inside this script the same name. In "use" operator you should use script name (you can think of it as of virtual file name) - the one you see in script list in the library. Then, you can call functions from that script using their respective names - name of the function may or may not be identical to script name. Note that each script has it's own main() function, even if you do not declare it explicitly, so you cannot call main() function of another script. One script may provide multiple functions, like in this example:
Script in the library called "MyScript":
/* function 1 */ sub f1(p) { println "f1 called with parameter " . p; } /* function 2 */ sub f2(p) { println "f2 called with parameter " . p; }and then you use it in some other script:
use MyScript; /* load script from library by it's name */ f1(1); /* call function f1 */ f2(2); /* call function f2 */Script above will produce output
f1 called with parameter 1 f2 called with parameter 2Best regards,
Victor -
-
No, it is not necessary. Empty main() will be created by script compiler if it was not defined explicitly.
Best regards,
Victor -
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login