UNSOLVED

commarla

updated

17 years ago

C

commarla

5 Posts

0

1680

October 16th, 2009 04:00

Unable to insert Criteria for SelectiveGroups in using perl API

Hello all,

I'am working on a script to adding automatically Selectivegroups to SAM.

To do that I'm using the perl API. Everything is working except the insertion of criteria (filters).

I've tried a lot of methods but I don't understand why it doesn't work.

Behind my script :


#!/usr/bin/perl

use InCharge::session;
use InCharge::object;
use Data::Dumper;

$DEBUG=1;

#
#Connexion à un DM
#conToSAM(broker,DM,username,password);
#
sub conToDM(){
$session=InCharge::session->new(
broker=>$_[0],
domain=>$_[1],
username=>$_[2],
password=>$_[3]
);
}
#
#Deconnexion du DM
#discoToDM();
#
sub discoToDM(){
$session->detach();
}
#
#
#
sub createGroup(){
$session->create("SelectiveGroup","HGRP-".$_[0]);
$obj=$session->object("SelectiveGroup","HGRP-".$_[0]);
open(RAA,"/opt/aqos/lco/scripts/regions/".$_[0]."_sousregions.txt")||die("marche pas");
$i=0;
@buffer="";
while( ){
$buffer[$i]=$_;
$i++;
}
close(RAA);
open(RAA2,"/opt/aqos/lco/scripts/regions/".$_[0]."_sousregionsNumber.txt")||die("marche pas");
$l=0;
@bufferNumber="";
while( ){
$bufferNumber[$l]=$_;
$l++;
}
close(RAA2);

@childs="";
@childstocreate="";
@selects="";

for $org (0..$#buffer){
$childs[$org]="SelectiveGroup::HGRP-".$_[0]."/".$buffer[$org];
$childstocreate[$org]="HGRP-".$_[0]."/".$buffer[$org];
$selects[$org]="ICF_GroupSelector::S-HGRP-".$_[0]."/".$buffer[$org];
}

chomp(@childs);
chomp(@childstocreate);
chomp(@selects);

for $or (0..$#childs){
print "create : ".$childstocreate[$or]."\n";
$session->create("SelectiveGroup",$childstocreate[$or]);
$session->create("ICF_GroupSelector","S-".$childstocreate[$or]);
}

$obj->put("IsTopLevel",1);
$obj->put("Description",$_[0].": 1");
$obj->put("DisplayName",$_[0]);
$obj->put("Generation",1);
$obj->insertElement("MemberOf","HierarchicalGroupManager::ICS-HierarchicalGroupManager");
$obj->put("TargetClass","UnitaryComputerSystem");
$obj->insertElement("ChildGroups",@childs);
$obj->insertElement("Selects",@selects);


####TEST###

$obj2=$session->object("SelectiveGroup","HGRP-RAA/URCAM d'Auvergne");
$obj2->put("DisplayName","URCAM d'Auvergne");
$obj2->put("Description","URCAM d'Auvergne : 63X");
$obj2->put("Generation",10);
$obj2->put("TargetClass","UnitaryComputerSystem");


$obj3=$session->object("ICF_GroupSelector","S-HGRP-RAA/URCAM d'Auvergne");
$obj3->put("SelectedBy","SelectiveGroup::HGRP-RAA");
$obj3->put("ChildGroup","SelectiveGroup::HGRP-RAA/URCAM d'Auvergne");
$obj3->put("Priority",0);

###HERE IS MY PROBLEM###
####BEGIN######
@name = ("Name","BB-*");
@vendor = ("Vendor","CISCO");
@criteria = ( \@name, \@vendor );
%criteria2=("Vendor"=>"CISCO","Name"=>"BB*");
%name3 = (Name=>"BB-*");
%vendor3 = (Vendor=>"CISCO");
%criteria3 = ( \@name, \@vendor );
$obj3->insertElement("criteria",@criteria);
#####END######
}

&conToDM("55.18.4.81","SUP-NAT-SAM","admin","changeme");
&createGroup("RAA");
&discoToDM();


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

I obtain two errors depending the code I use :

[6] Unknown argument (internal type 'Name') for InCharge primitive 'insertElement_P', stopped at /opt/aqos/lco/scripts/tmp.pl line 104

[6] Reference to 2-element array expected for argument to InCharge primitive 'insertElement_P', stopped at /opt/aqos/lco/scripts/tmp.pl line 104

the first one when I use the line : $obj3->insertElement("criteria",\@criteria);
and the second one with $obj3->insertElement("criteria",@criteria);


The script is launched with : /opt/InCharge7/SAM/smarts/bin/sm_perl /opt/aqos/lco/scripts/tmp.pl

I hope my explanation and my english are good.

By advance, thank you