1 2 Previous Next 18 Replies Latest reply on Apr 26, 2018 5:53 PM by Mroche

    Removing zeros from IP address on LDMS import

    Jamie Cannon ITSMMVPGroup

      I want to be able to do some right click stuff using Service Desk on a CI like Ping, TraceRt, HTML5 remote control using data pulled in from LDMS.  However, the issue I am having is that ping will respond to 10.0.9.15 but it won't respond to what LDMS pulls in for IP as 010.000.009.015.

       

      Has anyone found a way around this?  This post shows it can be done but not quite sure how.

       

      http://community.landesk.com/support/ideas/3286#comment-18351

       

      Thanks,

        • 1. Re: Removing zeros from IP address on LDMS import
          Expert

          Since your going to be using this as a link, might as well make a calculation to create the while link and remove unnecessary zeros along the way.  This way you can also check for bogus IP addresses like 192.168.0.1, 0.0.0.0, blank for an IP address, space at the beginning, etc, their going to be in there, I saw each of those in my first 100 CI's.

          • 2. Re: Removing zeros from IP address on LDMS import
            Jamie Cannon ITSMMVPGroup

            do you happen to have a calc or know of a calc that can remove uncessary zeros?  There has to be a way... just not THAT fluent in calcs yet.

            • 3. Re: Removing zeros from IP address on LDMS import
              Expert

              ZERO TESTING but something similar to ...

               

              import System

              static def GetAttributeValue(ConfigItem):

                  Value = ''

                  if ConfigItem._IPAddress is null:

                      Value = 'No IP address'

                      return Value

                  if ConfigItem._IPAddress == '000.000.000.000':

                      Value = 'No IP address'

                      return Value

                  for i in range(14):

                      if i = 0:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 1:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 2:

                          Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 3:

                          Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

               

                      if i = 4:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 5:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 6:

                          Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 7:

                          Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

               

               

                      if i = 8:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 9:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 10:

                          Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 11:

                          Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

               

               

                      if i = 12:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 13:

                          if ConfigItem._IPAddress.Substring[i,1] != '0':

                              Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                      if i = 14:

                          Value = Value + ConfigItem._IPAddress.Substring[i+1,1]

                         

                  return Value

               

              I start out by checking for null and all zeros and return immediately.  Then for each set of XXX. (4 sets) I check to see if the 1st character is a zero.  If not zero, I add it to Value (my working string).  I then check the second character for a zero and add if not a zero.  I always add the third character and if the 4th character (4th, 8th, and 12th) is a period, I add it as well.  The for loop starts at 0 so I have to add 1 to the string position (ie i=0, i+1 =1 so it's the first character of the string).

               

              More error checking could be done and testing for blanks but I think you get the idea from this.  I would probably make the calculation Before save and it would be dependent on the IP address.

              1 of 1 people found this helpful
              • 4. Re: Removing zeros from IP address on LDMS import
                Frank Wils ITSMMVPGroup

                Can you use vbscript? Data Analytics has a rule that creates Unpadded IP addresses on the LDMS side and uses this vbscript:

                 

                vals = Split(value, ".")

                for i = 0 to 3

                if instr(vals(i), "0") =1 and len(vals(i)) > 1 then

                  vals(i) = mid(vals(i), 2)

                end if

                if instr(vals(i), "0") =1  and len(vals(i)) > 1 then

                  vals(i) = mid(vals(i), 2)

                end if

                next

                retvalue = vals(0) + "." + vals(1) + "." + vals(2) + "." + vals(3)

                 

                 

                Frank

                • 5. Re: Removing zeros from IP address on LDMS import
                  Jamie Cannon ITSMMVPGroup

                  what is the .Substring?  when I test the calc I get an error "Field System.String.Substring' not found.

                  • 6. Re: Removing zeros from IP address on LDMS import
                    Jamie Cannon ITSMMVPGroup

                    Hi Frank,

                    It doesn't like vb unfortunately.  Service Desk calculations are based on the "BOO" language.  The customer doesn't have DA or I could just pull it from there already formatted.

                     

                    Thanks

                    • 7. Re: Removing zeros from IP address on LDMS import
                      Expert

                      They only support BOO.  It has many of the .NET functions but the formatting takes some getting used to.  There are no end statements because its all controlled by indenting.  It's more of a minimalist approach.  If you know VB script, your well on your way to knowing BOO.  LANDesk has some good guides for learning BOO and I highly recommend.  Their short, specific and have lots of examples.  After reading the 4-5 guides, it will make sense.  They also list the few specific Service Desk functions which are very handy.

                       

                      You will find these guides under Calculations on the right side of the Service Desk main page.

                      • 8. Re: Removing zeros from IP address on LDMS import
                        Expert

                        Calculation Writing Tutorial - 6.  Working with Strings

                        Getting a portion of a String using SubString()

                        The .Substring() Method is used to return a portion of a String.  You specify a Start Index and optionally a Length.  Start Index is the number of characters from the start to skip:

                         

                        Value = 'This is a String' CharSixOnwards = Value.Substring(5) JustCharNine = Value.Substring(8,1) 

                         

                        In the above examples the variable CharSixOnwards is set to "is a String".  The 5 used as its parameter tells it to skip the first 5 characters ('This ').  The variable JustCharNine is set to "a".  The first parameter tells it to skip the first 8 characters and the second parameter tells it to return 1 character from that point onwards.

                         

                        I got the same error but the above is from Stu's guide.

                        • 9. Re: Removing zeros from IP address on LDMS import
                          Jamie Cannon ITSMMVPGroup

                          Hmmm. very interesting. Thanks Carl

                          • 10. Re: Removing zeros from IP address on LDMS import
                            Jamie Cannon ITSMMVPGroup

                            It's a little longer but this seems to work:

                             

                            import System

                            static def GetAttributeValue(ConfigItem):

                                Value = ''

                                IPAddress = ConfigItem._IPAddress

                                Oct1 = ''

                                Oct2 = ''

                                Oct3 = ''

                                Oct4 = '.'

                                Oct5 = ''

                                Oct6 = ''

                                Oct7 = ''

                                Oct8 = '.'

                                Oct9 = ''

                                Oct10 = ''

                                Oct11 = ''

                                Oct12 = '.'

                                Oct13 = ''

                                Oct14 = ''

                                Oct15 = ''

                               

                                if IPAddress is null:

                                    Value = 'No IP Address'

                                    return Value

                                   

                                if IPAddress == '000.000.000.000':

                                    Value = 'No IP Address'

                                    return Value

                                   

                                if IPAddress != null and IPAddress.Substring(0,1) != '0':

                                    Oct1 = IPAddress.Substring(0,1)

                                if IPAddress != null:

                                    Oct2 = IPAddress.Substring(1,1)

                                if IPAddress != null:

                                    Oct3 = IPAddress.Substring(2,1)

                                   

                                if IPAddress != null and IPAddress.Substring(4,1) != '0':

                                    Oct5 = IPAddress.Substring(4,1)

                                if IPAddress != null and IPAddress.Substring(5,1) != '0':

                                    Oct6 = IPAddress.Substring(5,1)

                                if IPAddress != null:

                                    Oct7 = IPAddress.Substring(6,1)

                                   

                                if IPAddress != null and IPAddress.Substring(8,1) != '0':

                                    Oct9 = IPAddress.Substring(8,1)

                                if IPAddress != null and IPAddress.Substring(9,1) != '0':

                                    Oct10 = IPAddress.Substring(9,1)

                                if IPAddress != null:

                                    Oct11 = IPAddress.Substring(10,1)

                                   

                                if IPAddress != null and IPAddress.Substring(12,1) != '0':

                                    Oct13 = IPAddress.Substring(12,1)

                                if IPAddress != null and IPAddress.Substring(13,1) != '0':

                                    Oct14 = IPAddress.Substring(13,1)

                                if IPAddress != null:

                                    Oct15 = IPAddress.Substring(14,1)

                                   

                                return Oct1 + Oct2 + Oct3 + Oct4 + Oct5 + Oct6 + Oct7 + Oct8 + Oct9 + Oct10 + Oct11 + Oct12 + Oct13 + Oct14 + Oct15

                            • 11. Re: Removing zeros from IP address on LDMS import
                              Expert

                              Tested! 

                               

                              I made the most common mistakes.  Arggg!  '=' is not '==', very different.  '=' assigns a value and '==' tests values.  Then must use () and not [].  Looking closer, a 100 would become a 10 so additional if statements are needed on the 2nd digit of each section.  I got to let you have some fun.

                               

                              The debugger isn't perfect but boy is it really handy.  1000% better than what we had before.

                               

                              import System

                              static def GetAttributeValue(ConfigItem):

                                  Value = ''

                                  if ConfigItem._IPAddress is null:

                                      Value = 'No IP address'

                                      return Value

                                  if ConfigItem._IPAddress == '000.000.000.000':

                                      Value = 'No IP address'

                                      return Value

                                  for i in range(14):

                                      if i == 0:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 1:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 2:

                                          Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 3:

                                          Value = Value + ConfigItem._IPAddress.Substring(i,1)

                               

                               

                                      if i == 4:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 5:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 6:

                                          Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 7:

                                          Value = Value + ConfigItem._IPAddress.Substring(i,1)

                               

                               

                                      if i == 8:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 9:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 10:

                                          Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 11:

                                          Value = Value + ConfigItem._IPAddress.Substring(i,1)

                               

                               

                                      if i == 12:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 13:

                                          if ConfigItem._IPAddress.Substring(i,1) != '0':

                                              Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                      if i == 14:

                                          Value = Value + ConfigItem._IPAddress.Substring(i,1)

                                         

                                  return Value

                              • 12. Re: Removing zeros from IP address on LDMS import
                                Expert

                                One last quick tip on calculations.  Always save BEFORE you test the calculation.  If you get an error and it is unsaved, sometimes you lose the entire calculation and get the opportunity to type it all in again.  Save early and often.

                                • 13. Re: Removing zeros from IP address on LDMS import
                                  Stu McNeill Employee

                                  Hi all,

                                   

                                  I couldn't resist trying this to see how small the calc could really be.  I came up with the following:

                                   

                                  Value = "010.000.009.015"
                                  
                                  StringArray = Value.Split( char('.') )
                                  Numbers = []
                                  for s in StringArray:
                                            Numbers.Add( int.Parse(s) )
                                  
                                  return Numbers.Join('.')  // this returns a String with value "10.0.9.15"
                                  

                                   

                                  This works by splitting the IP address into an array, then for each section turn the value into an integer, then joining the array back into a string.  Turning the values into integers removes any leading zeros.

                                  • 14. Re: Removing zeros from IP address on LDMS import
                                    Jamie Cannon ITSMMVPGroup

                                    Very nice Stu.. very nice!

                                    1 2 Previous Next