UNSOLVED

savuka1

updated

17 years ago

S

savuka1

20 Posts

0

9402

September 16th, 2009 03:00

ASL script question

Hi,

I would like to make multiple queries for data using ASL and was wondering how I do this ASL.

Example:

I would like to extract all routers and then all cards associtaed with each of the routers.

Thanks in advance
James
  • Hemulll

    2 Intern

    •

    138 Posts

    1197

    0

    Posted September 16th, 2009 03:00

    Hi James,

    Example of asl script:

    START {
    .. eol
    }
    do {
    foreach router (getInstances("Router")) {
    routerObj = object(router);
    print("Router : ".routerObj->Name);
    cardObj = routerObj->getCards();
    if (!cardObj->isNull()) {
    print("Card : ".cardObj->Name);
    }
    }
    }
  • Hemulll

    2 Intern

    •

    138 Posts

    1197

    0

    Posted September 16th, 2009 04:00

    Sorry Boss, not tested.

    Fixed Code:

    START {
    .. eol
    }
    do {
    foreach router (getInstances("Router")) {
    routerObj = object(router);
    if (!routerObj->isNull()) {
    print("Router : ".routerObj->Name);
    cardList = list();
    cardList = routerObj->getCards();
    foreach card (cardList) {
    cardObj = object(card);
    if (!cardObj->isNull()) {
    print("Card : ".cardObj->Name);
    }
    }
    }
    }
    }
  • Hemulll

    2 Intern

    •

    138 Posts

    1197

    0

    Posted September 16th, 2009 04:00

    Hi James,

    Only a few points of happiness on this forum :-)
    Do u have ICQ, Skype etc ... ???
  • savuka1

    20 Posts

    1197

    0

    Posted September 16th, 2009 04:00

    Hi Hemul,

    Thanks, worked like a charm

    How much do I owe you ;-)

    James
  • savuka1

    20 Posts

    1197

    0

    Posted September 16th, 2009 04:00

    Hi Hemul

    I get the floowing error

    ASL-ERROR_OBJECT-Tried to perform a repository operation on a non-object

    I think it is todo with some routers not haveing cards, but looking at the code you would think that the if statement should handle that.

    Any ideas

    Kind Regards
    James
  • savuka1

    20 Posts

    1195

    0

    Posted September 16th, 2009 05:00

    Hi Hemul,

    Only skype at home , not allow to use it at work

    username is welljam

    my email address is james.wells@zxxx.com

    I have added a few more checks to the code.

    ####################################

    START {
    .. eol
    }
    do {
    foreach router (getInstances("Router"))
    {
    routerObj = object(router);
    if (!routerObj->isNull())
    {
    RouterStatus = (routerObj->IsUnmanagedOrUnresponsive);
    if ( RouterStatus != FALSE )
    {
    print("Router : ".routerObj->Name." IsUnManaged : ".routerObj->IsUnmanagedOrUnresponsive);
    }
    cardList = list();
    cardList = routerObj->getCards();
    foreach card (cardList)
    {
    cardObj = object(card);
    if (!cardObj->isNull())
    {
    Cardstatus = (cardObj->Status);
    if ( Cardstatus != "OK" )
    {
    print("Card : ".cardObj->Name." Status : ".cardObj->Status);
    }
    }
    }
    }
    }
    stop();
    }


    ####################################

    I had another question, is it possible to go through a list like routers and switches and not just routers and I also used a stop(); in my code , is this nessasary ?

    Kind Regards
    James

  • Hemulll

    2 Intern

    •

    138 Posts

    1195

    0

    Posted September 16th, 2009 06:00

    Hi James,

    Sure, you should use ICIM_UnitaryCumputerSystem insted router class, for example:



    foreach dev (getInstances(ICIM_UnitaryComputerSystem)) {
    devObj = object(dev);
    if (devObj->Type == Router || devObj->Type == Switch) {
    print(devObj->Name);
    }
    }

    Why do you need stop action ?
  • Hemulll

    2 Intern

    •

    138 Posts

    829

    0

    Posted September 16th, 2009 06:00

    Hi James,

    Sure, you should use ICIM_UnitaryCumputerSystem insted router class, for example:

    
    foreach dev (getInstances(ICIM_UnitaryComputerSystem)) {
              devObj = object(dev);
              if (devObj->Type == Router || devObj->Type == Switch) {
                             print(devObj->Name);
              }
    }
    


    Why do you need stop action ?
  • Hemulll

    2 Intern

    •

    138 Posts

    1492

    0

    Posted September 16th, 2009 07:00

    Hi James, exactly so,
    rapid writing always leads to the inevitable errors :-)

    No time for debug

    Message was edited by:
    Hemul
  • savuka1

    20 Posts

    1492

    0

    Posted September 16th, 2009 07:00

    Hi,

    The words Router and Switch for devObj->Type must be in uppercase it would seem as SMARTS ASL is case sensitive.

    Kind Regards
    James