0

Checking array for valid substrings from active directory

I have cretaed an array of valid substrings (ARY) and I need to check this against an array of server addresses (TST) to determine how many have valid domain addresses.  I have tried a number of differetn approaches but this seems close and clean in terms of code.  However it only returns 0 as a result.  What am I doing wrong.

7 replies

null
    • phillipsloper_mecom
    • 3 yrs ago
    • Reported - view

    This is the code I have developed.

    let a := this;
    let b := a.'App UID';
    let x := 0;
    let y := 0;
    let ARY := [".dpe.protected", ".dpesit.protected", ".dse.secret", ".dsesit.secret"];
    let TST := (select CMDBServers)['App UID' = b];
    let TSTcnt := cnt(TST);
    for i in TST do
    for j in ARY do
    if contains(i.Name, item(ARY, j)) then
    x := x + 1
    else
    y := y + 1
    end
    end
    end;
    alert("Non-Obsolete AD Servers = " + x + " out of " + TSTcnt);
    x / y * 100

    • Sean
    • 3 yrs ago
    • Reported - view

    I think the first two lines can be reduced to...

     

    let a := this.'App UID'

     

    When using for-loops, I have found you can only use the "for i in yourVariable do" syntax if the variable has been assigned a selection from a table like your TST variable. When an array has been assigned a value like your ARY array, you need to use the "for i in range(N, N) do" syntax or the "for i from N to N do" syntax.

    • phillipsloper_mecom
    • 3 yrs ago
    • Reported - view

    Sean 

     

    I tried this using the following code but got the same result.  Also tried converting the first loop to a while statement (while i < TSTidx do) but this equally failed.  Have i misread your guidance or am I issing something?

    let a := this;
    let b := a.'App UID';
    let x := 0;
    let y := 0;
    let i := 0;
    let ARY := [".dpe.protected", ".dpesit.protected", ".dse.secret", ".dsesit.secret"];
    let TST := (select CMDBServers)['App UID' = b];
    let TSTidx := cnt(TST);
    while i < TSTidx do 
    let TSTval := item(TST, i);
    for j from 0 to cnt(ARY) do
    if contains(TSTval.Name, item(ARY, j)) then
    x := x + 1
    else
    y := y + 1
    end
    end
    end
    ;
    alert("Non-Obsolete AD Servers = " + x + " out of " + TSTidx);
    x / y * 100
    end

    • phillipsloper_mecom
    • 3 yrs ago
    • Reported - view

    Error in pasting the code block; apologies.  Here is the latest one.

     

    let b := this.'App UID';
    let x := 0;
    let y := 0;
    let i := 0;
    let ARY := [".dpe.protected", ".dpesit.protected", ".dse.secret", ".dsesit.secret"];
    let TST := (select CMDBServers)['App UID' = b];
    let TSTidx := cnt(TST);
    for i in range(0, TSTidx) do
    let TSTval := item(TST, i);
    for j in range(0, cnt(ARY)) do
    if contains(TSTval.Name, item(ARY, j)) then
    x := x + 1
    else
    y := y + 1
    end
    end
    end;
    alert("Non-Obsolete AD Servers = " + x + " out of " + TSTidx);
    x / y * 100
    end

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    Hi,

    It seems that the original code contained a small error. This corrected version should work:

    let b := this.'App UID';
    let x := 0;
    let y := 0;
    let ARY := [".dpe.protected", ".dpesit.protected", ".dse.secret", ".dsesit.secret"];
    let TST := (select CMDBServers)['App UID' = b];
    let TSTcnt := cnt(TST);
    for i in TST do
    for j in ARY do
    if contains(i.Name, j) then x := x + 1 else y := y + 1 end
    end
    end;
    alert("Non-Obsolete AD Servers = " + x + " out of " + TSTcnt);
    x / y * 100

    • Sean
    • 3 yrs ago
    • Reported - view

    I just woke up and haven't had any coffee yet, but you can try this...

     

    let b := text(this.'App UID');
    let x := 0;
    let y := 0;
    let ARY := [".dpe.protected", ".dpesit.protected", ".dse.secret", ".dsesit.secret"];
    let TST := (select CMDBServers)['App UID' = b];
    let TSTcnt := cnt(TST);
    for i in TST do
    for j in range(0, count(ARY)) do
    if contains(text(i.Name), item(ARY, j)) then
    x := x + 1
    else
    y := y + 1
    end
    end
    end;
    alert("Non-Obsolete AD Servers = " + x + " out of " + TSTcnt);
    x / y * 100

    • phillipsloper_mecom
    • 3 yrs ago
    • Reported - view

    Thank you Sean awesome result especially without coffee!  It worked.

Content aside

  • 3 yrs agoLast active
  • 7Replies
  • 827Views