7 Replies Latest reply on Oct 17, 2017 12:39 PM by rednarb

    Hostname Variable for Configuration Template

    rednarb

      Friends,

       

      I need to pass the device's hostname to a command in a configuration template. I can't seem to find what the variable is to insert the hostname or system name into the CLI portion of the script! Any clues to lend? Ought to be simple but I can't find any example of it anywhere.

       

      For example:

       

      script SetLogPrefixJUNOS(NCM.Nodes @ContextNode, @HOSTNAME)

      {

        CLI

        {

           configure exclusive

           set system syslog host 10.1.1.1 log-prefix "@HOSTNAME"

           commit

           exit

        }

      }

       

        • Re: Hostname Variable for Configuration Template
          mesverrum

          Have you tried ${Caption} ?  the way you are using @hostname would seem to be trying to call a hostname that would have been given at the prompts before running the script, and I'm assuming you just want NCM to just automatically use the name from whatever node you are executing against.

            • Re: Hostname Variable for Configuration Template
              rednarb

              Thank you for the suggestion however, I have just tried that and it doesn't validate.

               

              set system syslog host 10.1.1.1 log-prefix "${Caption}"

               

              Validation Failed: An error occurred during script parsing. Position: Line 19, Character 61 Error message: no viable alternative at character '"' Please check script syntax.

               

               

                  • Re: Hostname Variable for Configuration Template
                    rednarb

                    No joy.

                     

                    I tried:

                    set system syslog host 10.1.1.1 log-prefix @ContextNode.Caption

                     

                    Got:

                    Error:Variable @ContextNode.Caption could not be matched. Possible causes of this are:

                    1) It has not been declared.

                    2) You are referencing an entity property which does not exist.

                    3) You are missing a closing bracket in a prior native block.

                     

                    I'm going to tinker around with variable declaration and see if I can make this work but there is surprisingly little or cryptic (to my pea brain at least) information on this out there!

                      • Re: Hostname Variable for Configuration Template
                        mesverrum

                        Yeah, I've done this stuff before but it is so few and far between for me I have forgotten the syntax.  I've just been too lazy to log into my lab server and try to build a template using one of these to jog my memory, was hoping quick google fu would save me from work.  I'll let you know if I come across the syntax when I get into the lab later this week.

                          • Re: Hostname Variable for Configuration Template
                            mesverrum

                            I figured it out, dumb.  NCM has a different nodes table than the main orion modules use, i looked at that table and they have different names for some things, for example they call the Caption as NodeCaption, i tested that and it worked

                             

                            Any of these should work from the contextnode. syntax

                             

                            NodeID, CoreNodeID, EngineID, NodeCaption, NodeGroup, AgentIP, AgentIPv6, ManagedProtocol, AgentIPSort, ReverseDNS, Status, Community, CommunityReadWrite, SNMPLevel, SysName, SysDescr, SysContact, SysLocation, SystemOID, Vendor, VendorIcon, MachineType, LastBoot, OSImage, OSVersion, ConfigTypes, NodeComments, Username, Password, EnableLevel, EnablePassword, ExecProtocol, CommandProtocol, TransferProtocol, LoginStatus, UseHTTPS, UseUserDeviceCredentials, LastInventory, SNMPContext, SNMPUsername, SNMPAuthType, SNMPAuthPass, SNMPEncryptType, SNMPEncryptPass, AllowIntermediary, UseKeybInteractiveAuth, ResponseError, InstanceType, plus any custom properties you have created in your environment

                             

                            -Marc Netterfield

                                Loop1 Systems: SolarWinds Training and Professional Services

                              • Re: Hostname Variable for Configuration Template
                                rednarb

                                Wow, thank you so much for your help. Way above and beyond Marc!

                                 

                                For the record, here is the working little script:

                                /*

                                .CHANGE_TEMPLATE_DESCRIPTION

                                        Set syslog log-prefix for Juniper JUNOS devices

                                .PLATFORM_DESCRIPTION

                                        Juniper JUNOS

                                .PARAMETER_LABEL @ContextNode

                                        NCM Node

                                .PARAMETER_DESCRIPTION @ContextNode

                                        The node the template will operate on.  All templates require this by default. The target node is selected during the first part of the wizard so it will not be available for selection when defining values of variables.

                                */

                                 

                                 

                                script SetLogPrefixJUNOS(  

                                                             NCM.Nodes @ContextNode)

                                {

                                  CLI

                                  {

                                     configure exclusive

                                     set system syslog host X.X.X.X log-prefix @ContextNode.NodeCaption

                                     commit

                                     exit

                                  }

                                }