Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Alarms

Alarms

Scheduled Pinned Locked Moved Support
17 Posts 2 Posters 24.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L
    L
    lindeamon
    wrote on last edited by
    #5

    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

    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #6

      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

      1 Reply Last reply
      0
      • L
        L
        lindeamon
        wrote on last edited by
        #7

        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

        1 Reply Last reply
        0
        • V
          V
          Victor Kirhenshtein
          wrote on last edited by
          #8

          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

          1 Reply Last reply
          0
          • L
            L
            lindeamon
            wrote on last edited by
            #9

            hi victor,

            i think i understand.i will give it a try.
            b.t.w - a feature request regarding this subject - the ability to copy/paste scripts.

            Best Regards,
            Lindeamon

            1 Reply Last reply
            0
            • L
              L
              lindeamon
              wrote on last edited by
              #10

              hi victor,

              no luck.
              i have created 2 scripts:

              1. 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";
                    }
                    }
              2. 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

              1 Reply Last reply
              0
              • L
                L
                lindeamon
                wrote on last edited by
                #11

                and i forgot to mention that once i have tried the above configuration the server crashed.

                1 Reply Last reply
                0
                • V
                  V
                  Victor Kirhenshtein
                  wrote on last edited by
                  #12

                  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

                  1 Reply Last reply
                  0
                  • L
                    L
                    lindeamon
                    wrote on last edited by
                    #13

                    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

                    1 Reply Last reply
                    0
                    • V
                      V
                      Victor Kirhenshtein
                      wrote on last edited by
                      #14

                      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 2
                      

                      Best regards,
                      Victor

                      1 Reply Last reply
                      0
                      • L
                        L
                        lindeamon
                        wrote on last edited by
                        #15

                        hi victor,

                        thank you for the clarification although there is one thing i do not understand.
                        do i have to begin the script with:
                        sub main()
                        {
                        }

                        and then write the other functions i want to use ?

                        Best Regards,
                        Lindeamon

                        1 Reply Last reply
                        0
                        • V
                          V
                          Victor Kirhenshtein
                          wrote on last edited by
                          #16

                          No, it is not necessary. Empty main() will be created by script compiler if it was not defined explicitly.

                          Best regards,
                          Victor

                          1 Reply Last reply
                          0
                          • L
                            L
                            lindeamon
                            wrote on last edited by
                            #17

                            thank you very much

                            Best Regards,
                            Lindeamon

                            1 Reply Last reply
                            0

                            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
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            Powered by NodeBB Contributors
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups