nv-l
[Top] [All Lists]

RE: Find object...

To: nv-l@lists.tivoli.com
Subject: RE: Find object...
From: "MERY Olivier (Neuilly Gestion)" <olivier.mery@cetelem.fr>
Date: Fri, 21 Apr 2000 09:17:33 +0200
You can do a Locate by attribute thru the gui.
The name of the attribute is "SNMP ifPhysAddr".

... or you can do it thru command line if you compile
this small home made utility... It works on any number of fields
of any type.
for example : FindObject "SNMP ifPhysAddr=0x0123456789AB"

Olivier

############################################################################
#########
#include <strings.h>
#include <stdio.h>
#include <netinet/in.h>
#include <OV/ovw_obj.h>
#include <OV/ovw.h>

/**************************************************
*       Programme de recherche de la liste des
*       objets ayant les caracteristiques listees
*       en parametres, dans la base NV6000
**************************************************/

main(argc,argv)
int argc;
char **argv;
{

char *strlower(char *);
int argvl,rc,i,efv;
long ia,is;
OVwFieldId f_id,snf_id,tnf_id,inf_id,iaf_id,isf_id,ticf_id,tilf_id;
OVwFieldBindList fbl;
OVwFieldBinding *fb_ptr,*p;
OVwObjectIdList *list;
OVwObjectId ObjectId;
char chaine[64], *fieldname, *fieldvalue, *item;
OVwFieldInfo *f_info;
OVwFieldValue *f_val;

if (argc == 1)
        {
        fprintf(stderr,"Usage : FindObject [-d] FieldName=value [...]\n");
        exit(1);
        }

/* connexion a OVwDb */
rc=OVwDbInit();
if (rc < 0)
  {
  printf("Connexion a OVwDb failed \"%s\" \n",OVwErrorMsg(OVwError()));
  exit(2);
  }

fbl.count=argc-1;
fbl.fields=( OVwFieldBinding *) malloc( (argc-1) * sizeof(OVwFieldBinding
));
p=fbl.fields;

for (i=1; i<argc; i++)
{

/*fprintf(stderr,"argv[%d]=%s\n",i,argv[i]);*/

argvl=strlen(argv[i]);
fieldname=strtok(argv[i],"=");
if(argvl==strlen(argv[i])) {
 fprintf(stderr,"Usage : FindObject FieldName=value [...]\n");
 exit(1);
}
/*fprintf(stderr,"fieldname=%s\n",fieldname);*/

if(*fieldname=='"') fieldname++;
fieldvalue=argv[i]+strlen(fieldname)+1;
if(*(fieldvalue+strlen(fieldvalue))=='"') {
 *(fieldvalue+strlen(fieldvalue))='\0';
}
/*fprintf(stderr,"fieldvalue=%s\n",fieldvalue);*/
f_id = OVwDbFieldNameToFieldId(fieldname);
if (OVwIsIdNull(f_id)) {
 fprintf(stderr,"fieldname=%s\n",fieldname);
 fprintf(stderr,"%s\n",OVwErrorMsg(OVwError()));
 exit(4);
}
p->field_id = f_id;
f_info = OVwDbGetFieldInfo(f_id);
p->field_val = (OVwFieldValue *) malloc( sizeof(OVwFieldValue) );
switch(f_info->field_type) {
case ovwIntField :
  for(i=0; i<strlen(fieldvalue); i++)
    if(!isdigit(*(fieldvalue+i))) {
      exit(5);
      break;
    }

  p->field_val->un.int_val = atoi(fieldvalue);
  p->field_val->field_type = ovwIntField;
  break;

case ovwBooleanField :
  fieldvalue=strlower(fieldvalue);
  if(!strcasecmp(fieldvalue, "true") ||
     !strcasecmp(fieldvalue, "t") ||
     !strcmp(fieldvalue, "1"))
    p->field_val->un.bool_val = TRUE;
  else
  if(!strcasecmp(fieldvalue, "false") ||
     !strcasecmp(fieldvalue, "f") ||
     !strcmp(fieldvalue, "0"))
    p->field_val->un.bool_val = TRUE;
  else exit(5);

  p->field_val->field_type = ovwBooleanField;
  break;

case ovwStringField :
  p->field_val->un.string_val = fieldvalue;
  p->field_val->field_type = ovwStringField;
  break;

case ovwEnumField :
  efv=OVwDbGetEnumValue(f_id,fieldvalue);
  p->field_val->un.enum_val = (efv==-1) ? atoi(fieldvalue) : efv;
  p->field_val->field_type = ovwEnumField;
  break;

default:
  exit(7);
}
if(f_info) OVwDbFreeFieldInfo(f_info);

p->field_val->is_list = FALSE;

p=fbl.fields+i;
}

list = OVwDbListObjectsByFieldValues(&fbl);
if (list == NULL)
        {
        fprintf(stderr,"%s\n",OVwErrorMsg(OVwError()));
        exit(8);
        }

snf_id = OVwDbFieldNameToFieldId("Selection Name");
inf_id = OVwDbFieldNameToFieldId("IP Name");
tnf_id = OVwDbFieldNameToFieldId("TopM Node ID");
ticf_id = OVwDbFieldNameToFieldId("TopM Interface Count");
tilf_id = OVwDbFieldNameToFieldId("TopM Interface List");
iaf_id = OVwDbFieldNameToFieldId("IP Address");
isf_id = OVwDbFieldNameToFieldId("IP Subnet Mask");

for (i=0; i<list->count; i++)
        {
         if (f_val=OVwDbGetFieldValue(list->object_ids[i],tnf_id)) {
 
ia=inet_addr(OVwDbGetFieldStringValue(list->object_ids[i],iaf_id));
 
is=inet_addr(OVwDbGetFieldStringValue(list->object_ids[i],isf_id));
          printf("%s %s
",inet_ntoa(ia&is),OVwDbGetFieldStringValue(f_val->field
_int_val,inf_id));
          OVwDbFreeFieldValue(f_val);
         }
         else if
(OVwDbGetFieldIntegerValue(list->object_ids[i],ticf_id)!=-1) {
          f_val=OVwDbGetFieldValue(list->object_ids[i],tilf_id);
          item=f_val->field_list_val->list->field_string_val;
          strtok(item," ");strtok(NULL," ");
          ia=inet_addr(strtok(NULL," "));
          is=inet_addr(strtok(NULL," "));
          printf("%s %s
",inet_ntoa(ia&is),OVwDbGetFieldStringValue(f_val->field
_int_val,inf_id));
          OVwDbFreeFieldValue(f_val);
         }
        printf("%s\n",OVwDbGetFieldStringValue(list->object_ids[i],snf_id));
        }
exit(0);
}

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

Tel.    : +33146399729 
Fax     : +33146391554 
Email   : <mailto:olivier.mery@cetelem.fr> 

Olivier MERY 
CETELEM 
20, avenue Georges Pompidou 
92595 LEVALLOIS-PERRET Cedex 



-----Original Message-----
From: Marcelo Pastre [mailto:mpastre@power.ufscar.br]
Sent: Thursday, April 20, 2000 8:17 PM
To: IBM NetView Discussion
Subject: [NV-L] Find object...


Hi folks...
How do I do to find objects by physical address of card network?
This is different that the number of the "link address", isn't this?
I have the physical address but I don't find this object...
Can anybody help me??

Thanks,
Marcelo.
_________________________________________________________________________

NV-L List information (unsubscribing, policies, posting, digest version,
searchable archives): http://www.tkg.com/nv-l

You can do a Locate by attribute thru the gui.
The name of the attribute is "SNMP ifPhysAddr".

... or you can do it thru command line if you compile
this small home made utility... It works on any number of fields
of any type.
for example : FindObject "SNMP ifPhysAddr=0x0123456789AB"

Olivier

#####################################################################################
#include <strings.h>
#include <stdio.h>
#include <netinet/in.h>
#include <OV/ovw_obj.h>
#include <OV/ovw.h>

/**************************************************
*       Programme de recherche de la liste des
*       objets ayant les caracteristiques listees
*       en parametres, dans la base NV6000
**************************************************/

main(argc,argv)
int argc;
char **argv;
{

char *strlower(char *);
int argvl,rc,i,efv;
long ia,is;
OVwFieldId f_id,snf_id,tnf_id,inf_id,iaf_id,isf_id,ticf_id,tilf_id;
OVwFieldBindList fbl;
OVwFieldBinding *fb_ptr,*p;
OVwObjectIdList *list;
OVwObjectId ObjectId;
char chaine[64], *fieldname, *fieldvalue, *item;
OVwFieldInfo *f_info;
OVwFieldValue *f_val;

if (argc == 1)
        {
        fprintf(stderr,"Usage : FindObject [-d] FieldName=value [...]\n");
        exit(1);
        }

/* connexion a OVwDb */
rc=OVwDbInit();
if (rc < 0)
  {
  printf("Connexion a OVwDb failed \"%s\" \n",OVwErrorMsg(OVwError()));
  exit(2);
  }

fbl.count=argc-1;
fbl.fields=( OVwFieldBinding *) malloc( (argc-1) * sizeof(OVwFieldBinding ));
p=fbl.fields;

for (i=1; i<argc; i++)
{                                                                             
/*fprintf(stderr,"argv[%d]=%s\n",i,argv[i]);*/

argvl=strlen(argv[i]);
fieldname=strtok(argv[i],"=");
if(argvl==strlen(argv[i])) {
 fprintf(stderr,"Usage : FindObject FieldName=value [...]\n");
 exit(1);
}
/*fprintf(stderr,"fieldname=%s\n",fieldname);*/

if(*fieldname=='"') fieldname++;
fieldvalue=argv[i]+strlen(fieldname)+1;
if(*(fieldvalue+strlen(fieldvalue))=='"') {
 *(fieldvalue+strlen(fieldvalue))='\0';
}
/*fprintf(stderr,"fieldvalue=%s\n",fieldvalue);*/
f_id = OVwDbFieldNameToFieldId(fieldname);
if (OVwIsIdNull(f_id)) {
 fprintf(stderr,"fieldname=%s\n",fieldname);
 fprintf(stderr,"%s\n",OVwErrorMsg(OVwError()));
 exit(4);
}
p->field_id = f_id;
f_info = OVwDbGetFieldInfo(f_id);
p->field_val = (OVwFieldValue *) malloc( sizeof(OVwFieldValue) );
switch(f_info->field_type) {
case ovwIntField :
  for(i=0; i<strlen(fieldvalue); i++)
    if(!isdigit(*(fieldvalue+i))) {
      exit(5);
      break;
    }

  p->field_val->un.int_val = atoi(fieldvalue);
  p->field_val->field_type = ovwIntField;
  break;

case ovwBooleanField :
  fieldvalue=strlower(fieldvalue);
  if(!strcasecmp(fieldvalue, "true") ||
     !strcasecmp(fieldvalue, "t") ||
     !strcmp(fieldvalue, "1"))
    p->field_val->un.bool_val = TRUE;
  else
  if(!strcasecmp(fieldvalue, "false") ||
     !strcasecmp(fieldvalue, "f") ||
     !strcmp(fieldvalue, "0"))
    p->field_val->un.bool_val = TRUE;
  else exit(5);                                                               
  p->field_val->field_type = ovwBooleanField;
  break;

case ovwStringField :
  p->field_val->un.string_val = fieldvalue;
  p->field_val->field_type = ovwStringField;
  break;

case ovwEnumField :
  efv=OVwDbGetEnumValue(f_id,fieldvalue);
  p->field_val->un.enum_val = (efv==-1) ? atoi(fieldvalue) : efv;
  p->field_val->field_type = ovwEnumField;
  break;

default:
  exit(7);
}
if(f_info) OVwDbFreeFieldInfo(f_info);

p->field_val->is_list = FALSE;

p=fbl.fields+i;
}

list = OVwDbListObjectsByFieldValues(&fbl);
if (list == NULL)
        {
        fprintf(stderr,"%s\n",OVwErrorMsg(OVwError()));
        exit(8);
        }

snf_id = OVwDbFieldNameToFieldId("Selection Name");
inf_id = OVwDbFieldNameToFieldId("IP Name");
tnf_id = OVwDbFieldNameToFieldId("TopM Node ID");
ticf_id = OVwDbFieldNameToFieldId("TopM Interface Count");
tilf_id = OVwDbFieldNameToFieldId("TopM Interface List");
iaf_id = OVwDbFieldNameToFieldId("IP Address");
isf_id = OVwDbFieldNameToFieldId("IP Subnet Mask");

for (i=0; i<list->count; i++)
        {
         if (f_val=OVwDbGetFieldValue(list->object_ids[i],tnf_id)) {
          ia=inet_addr(OVwDbGetFieldStringValue(list->object_ids[i],iaf_id));
          is=inet_addr(OVwDbGetFieldStringValue(list->object_ids[i],isf_id));
          printf("%s %s ",inet_ntoa(ia&is),OVwDbGetFieldStringValue(f_val->field
_int_val,inf_id));
          OVwDbFreeFieldValue(f_val);
         }
         else if (OVwDbGetFieldIntegerValue(list->object_ids[i],ticf_id)!=-1) {
          f_val=OVwDbGetFieldValue(list->object_ids[i],tilf_id);
          item=f_val->field_list_val->list->field_string_val;
          strtok(item," ");strtok(NULL," ");
          ia=inet_addr(strtok(NULL," "));
          is=inet_addr(strtok(NULL," "));
          printf("%s %s ",inet_ntoa(ia&is),OVwDbGetFieldStringValue(f_val->field
_int_val,inf_id));
          OVwDbFreeFieldValue(f_val);
         }
        printf("%s\n",OVwDbGetFieldStringValue(list->object_ids[i],snf_id));
        }
exit(0);
}

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

Tel.    : +33146399729
Fax     : +33146391554
Email   : <mailto:olivier.mery@cetelem.fr>

Olivier MERY
CETELEM
20, avenue Georges Pompidou
92595 LEVALLOIS-PERRET Cedex



-----Original Message-----
From: Marcelo Pastre [mailto:mpastre@power.ufscar.br]
Sent: Thursday, April 20, 2000 8:17 PM
To: IBM NetView Discussion
Subject: [NV-L] Find object...


Hi folks...
How do I do to find objects by physical address of card network?
This is different that the number of the "link address", isn't this?
I have the physical address but I don't find this object...
Can anybody help me??

Thanks,
Marcelo.
_________________________________________________________________________

NV-L List information (unsubscribing, policies, posting, digest version,
searchable archives): http://www.tkg.com/nv-l

<Prev in Thread] Current Thread [Next in Thread>

Archive operated by Skills 1st Ltd

See also: The NetView Web