choefing

updated

17 years ago

C

choefing

1 Rookie

•

49 Posts

0

1585

June 11th, 2009 16:00

How to add/create a device using perl ?

Hi everybody,

when using Domain Manager on sm_gui or sm_tpmgr I only have to provide a minimum of information, e.g. hostname/ip and accessmode only. The "apply some magic"-machine behind that is taking care of all the necessary operations.
Is there any simple perl API function built in providing nearly the same functionality ?

I wrote a script fetching some hosts, which should be added to the repository... thats the plan so far.

I tried to figure out what I can do with the already known features.

a) $object = $session->create ( "Host", "somehost" ); what of course creates a "somehost" within "Host" which is nearly empty.
Now I can fill in all the values (what values are at least needed to get it discovered / set it to pending list?), using several operations available for "Host" like setAccessMode or makeIP .. and finally.. find something to discover it or put it on the pending list. (hints on that will be fine too)
But that does not seem the way it's meant to be to me.

b) I can also write my data into a file, used as seedfile when invoking a system command from the script, say.. let perl invoke sm_tpmgr -s DOMAIN --seed=/path/to/seed.file

. but.. as already wrote in a) .. doesn't seem the way..

Didn't found a proper discripton of what I expected / was looking for in the perl API documentaion.

Any hints on that ?

Thanks & rgds
Christian
  • TCorcoran

    53 Posts

    437

    0

    Posted June 11th, 2009 16:00

    You will need to create an object manager refference and then use the addPending operation

    $topoManagerRef = $session->object("ICF_TopologyManager::ICF-TopologyManager");
    $topoManagerRef->addPending($name,$community,$text,"TM_USERADDED","TM_SNMP",161,"ICMPSNMP");

    That will add it to the pending discovery queue and allow the behind the scenes magic to do the rest.

    - TC
  • choefing

    1 Rookie

    •

    49 Posts

    437

    0

    Posted June 11th, 2009 16:00

    Thanks TC, works like a charm. :-)

    Maybe you can point me to the part of the documentation I missed ? The getOper of ICF_TopologyManager seems a little bit confusing me because of the options. More detailed information would be nice... TM_USERADDED.. and. whatever else

    This solution points me to another part of the doku...

    delete
    $obj->delete( )
    Deletes the specified item from the repository, but without performing any clean-up
    of inter-object dependencies.
    Consider using the remove() operation, if one exists, instead for a more complete
    action.

    But no information about a remove() function. Maybe also any hints on that ?

    EDIT: is this one meant ?
    $ dmctl -s DOMAIN getOper Host | grep remove
    remove


    Thanks & rgds
    Christian

    Message was edited by:
    choefing
  • choefing

    1 Rookie

    •

    49 Posts

    437

    0

    Posted June 11th, 2009 17:00

    So its too straight forward to be worth to add it to the documentation ? ;-)


    Just figured it out, remove() works as well as
    $topoManagerRef->discoverPending();
    or
    $topoManagerRef->rediscover($host);

    As long as the device is on the pending list, a rediscover works.


    There is another option
    insertIntoShortDiscoveryQueue agentObj
    but not sure what this does exactly.

    Thanks a lot TC

    Message was edited by:
    choefing
  • TCorcoran

    53 Posts

    437

    0

    Posted June 11th, 2009 17:00

    The "TM_USERADDED" I actually got from support some time ago when I was wrestling with the same issue.

    The remove operation is pretty straightforward,

    $object->remove();

    Thats all you need.

    - TC
  • Hemulll

    2 Intern

    •

    138 Posts

    437

    0

    Posted June 12th, 2009 00:00

    Hi all,

    I use addPending with full options.
    TC, i have no see short options for addPending function :-)

    # -- Create session to APM server

    $apm_session = InCharge::session->init(

    broker=>"127.0.0.1",

    domain=>"apm",

    username=>"admin",

    password=>"changeme"

    );



    $sm_apmNodeObj = $apm_session->object($class,$name);

    if ($sm_apmNodeObj->isNull()) {

    print " Object $class $name is null\n";

    return;

    }

    $snmpObj = $sm_apmNodeObj->getSNMPAgent();

    $snmpObj = $apm_session->object($snmpObj);

    print "Host Services is $snmpObj->{Name}\n";



    $manager = $apm_session->object($apm_session->getInstances("ICF_TopologyManager"));

    $factory = $apm_session->object($apm_session->getInstances("ICIM_ObjectFactory"));



    # -- rediscover device in APM server

    $manager->addPending($sm_apmNodeObj->{Name}, $sm_apmNodeObj->{ReadCommunity}, "xDiscovery" , "TM_USERADDED" ,"TM_SNMP" , $snmpObj->{PortNumber} , $sm_apmNodeO

    bj->{AccessMode} , "UNKNOWNADDRESSFORMAT", $snmpObj->{SeedName}, $nameFormat, $snmpObj->{SNMPVersion}, $snmpObj->{User}, $snmpObj->{EngineID} , $snmpObj->{Aut

    hProtocol}, $snmpObj->{PrivProtocol}, $snmpObj->{AuthPass}, $snmpObj->{PrivPass}, "", 1, $snmpObj->{DisplayName}, $sm_apmNodeObj->{Type}, $sm_apmNodeObj->{Dom

    ain}, $sm_apmNodeObj->{SourceAddress} );





    print "Device $sm_apmNodeObj->{DisplayName} added to Pending List\n";



    $apm_session->detach();
  • choefing

    1 Rookie

    •

    49 Posts

    437

    0

    Posted June 12th, 2009 06:00

    Hi Hemul,

    just finished my script with nothing in as

    my $topoManagerRef = $session->object("ICF_TopologyManager::ICF-TopologyManager");
    $topoManagerRef->addPending( $host, $accessMode, $text);

    EDIT: works until discover process started, then it fails with "does not pass filter". so i have to stick on your sniplets to get it work.

    what works without any problems for ICMPONLY devices (what was the intention for me)

    $host can be resolveavle hostname or IP
    $accessMode is set to ICMPONLY
    $text just shows the "whatever you entered here" in the comment-line when watching discovery process.

    But anyway. thanks for your sniplets, I guess as soon as my boss notice whats possible with perl I have to do a lot more and maybe need those hints as well.

    Thx & rgds
    Christian

    Message was edited by:
    choefing