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

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

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

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

ZERO TESTING but something similar to ...

import System

static def GetAttributeValue(ConfigItem):

Value = ''

return Value

return Value

for i in range(14):

if i = 0:

if i = 1:

if i = 2:

if i = 3:

if i = 4:

if i = 5:

if i = 6:

if i = 7:

if i = 8:

if i = 9:

if i = 10:

if i = 11:

if i = 12:

if i = 13:

if i = 14:

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

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

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

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

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.

## 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

Hmmm. very interesting. Thanks Carl

• ###### 10. Re: Removing zeros from IP address on LDMS import

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

import System

static def GetAttributeValue(ConfigItem):

Value = ''

Oct1 = ''

Oct2 = ''

Oct3 = ''

Oct4 = '.'

Oct5 = ''

Oct6 = ''

Oct7 = ''

Oct8 = '.'

Oct9 = ''

Oct10 = ''

Oct11 = ''

Oct12 = '.'

Oct13 = ''

Oct14 = ''

Oct15 = ''

return Value

return Value

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

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 = ''

return Value

return Value

for i in range(14):

if i == 0:

if i == 1:

if i == 2:

if i == 3:

if i == 4:

if i == 5:

if i == 6:

if i == 7:

if i == 8:

if i == 9:

if i == 10:

if i == 11:

if i == 12:

if i == 13:

if i == 14:

return Value

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

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

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: