nv-l
[Top] [All Lists]

Re: Extracting just a single field from objdb???

To: nv-l@lists.tivoli.com
Subject: Re: Extracting just a single field from objdb???
From: Ray Schafer <schafer@tkg.com>
Date: Thu, 18 Nov 1999 13:32:28 -0600
Jeff Fitzwater wrote:

> NV 5.1.2 on Solaris 2.6
>
> How can I get all the info for just a single FIELD of a specific node in
> the OBJDB?
>
> I want to extract just the Interface list FIELD ID 177.

I made some minor changes to the version I just sent out so it will do
better error checking and supply better debugging info.


--
Ray Schafer                   | schafer@tkg.com
The Kernel Group              | Distributed Systems Management
http://www.tkg.com


/*
   Compile with:
   (g)cc -I /usr/OV/include -L/usr/OV/lib -o listfld listfld.c -lovw -lov -lntl
   Given the selection name, list the field value.
   By Ray Schafer, TKG <schafer@tkg.com>
*/

#include <stdio.h>
#include <sys/time.h>
#include <OV/ovw.h>

static char const rcsid[] =
"@(#)$Id: listfld.c,v 1.5 1999/11/18 19:19:00 schafer Rel $";

main(int argc, char *argv[])
{
   OVwFieldId FldID;
   OVwFieldInfo *FieldInfo;
   OVwObjectId OID;
   OVwFieldValue *val_ptr;
   char *SelName;
   char *FldName;
   int c;
   int i;
   int Debug = 0;
   int Type;
   extern int optind;
   extern char *optarg;
   int errflg = 0;
   int FldIdSet = 0;

   char *FldType[11];
   FldType[1] = "Integer";
   FldType[2] = "Boolean";
   FldType[3] = "String";
   FldType[4] = "Enumerated";

   OVwDbInit();

   while ((c = getopt(argc, argv, "o:s:f:i:d")) != EOF)
   {
      switch (c)
      {
         case 'o':
            OID = (OVwObjectId ) atoi(optarg);
            SelName = OVwDbObjectIdToSelectionName (OID);
            if (SelName == NULL) {
                fprintf (stderr, "Cannot convert Object ID %s into a Selection 
Name: %s\n",
                    optarg, OVwErrorMsg(OVwError()));
                usage (basename (argv[0]));
            }
            break;

         case 's':
            SelName = optarg;
            /* Get the object ID of the Selection Name */
            OID = OVwDbSelectionNameToObjectId(optarg);
            /* Verifies the object ID is available from the database */
            if ( OVwIsIdNull(OID) ) {
                fprintf( stderr, "Error converting \"%s\" to Object ID: %s\n",
                      SelName, OVwErrorMsg(OVwError()));
                usage(basename(argv[0]));
            }
            break;

         case 'f':
            FldName = optarg;
            FldID = OVwDbFieldNameToFieldId(FldName);
            /* Verifies the Field ID is available from the database */
            if ( OVwIsIdNull(FldID) ) {
                fprintf( stderr, "Error converting \"%s\" to Field ID: %s\n",
                FldName, OVwErrorMsg(OVwError()));
                usage(basename(argv[0]));
            }
            break;

         case 'i':
            FldID = (OVwFieldId ) atoi (optarg);
            FldName = OVwDbFieldIdToFieldName (FldID);
            if ( FldName == NULL ) {
                fprintf( stderr, "Error converting \"%s\" to Field ID: %s\n",
                optarg, OVwErrorMsg(OVwError()));
                usage(basename(argv[0]));
            }
            break;


         case 'd':
            Debug = 1;
            break;

         default:
            usage(basename(argv[0]));
      }
   }
   /* Usage Checks */
   if (argc <= 2) usage(basename(argv[0]));
   if ((OVwIsIdNull (FldID)) || (OVwIsIdNull (OID))) usage(basename(argv[0]));

   /* Find out what type of Field this is, call the appropriate API routine */
   FieldInfo =  OVwDbGetFieldInfo(FldID);
   Type = FieldInfo->field_type;
   val_ptr = OVwDbGetFieldValue (OID, FldID);
   if ( val_ptr == NULL ) {
       fprintf( stderr, "Error determining value for field %s for ObjectID %d: 
%s\n",
             FldName, OID, OVwErrorMsg(OVwError()));
       exit (1);
   }
   if (Debug) {
       fprintf (stderr, "Object ID = %d, Field ID = %d\n", OID, FldID);
       fprintf (stderr, "Selection Name = %s, Field Name = %s\n", SelName, 
FldName);
       fprintf (stderr, "Field Type is %s\n", FldType[Type]);
       if (val_ptr->is_list) {
           fprintf (stderr, "Field is a list Field with %d value(s)\n", 
val_ptr->un.list_val->count);
           fprintf (stderr, "Value(s):\n");
       }
       else fprintf (stderr, "Value is:\n");
   }
   switch ( Type ) {
      case ovwStringField:
          if (val_ptr->is_list) {
              for (i = 1;i <= val_ptr->un.list_val->count; i++, 
val_ptr->un.list_val->list++ ) {
                  printf( "%s\n", val_ptr->un.list_val->list->un.string_val);
              }
          }
          else {
              printf( "%s\n", val_ptr->un.string_val );
          }
          break;
      case ovwIntField:
          if (val_ptr->is_list) {
              for (i = 1;i <= val_ptr->un.list_val->count; i++, 
val_ptr->un.list_val->list++ ) {
                  printf( "%d\n", val_ptr->un.list_val->list->un.int_val);
              }
          }
          else {
              printf( "%d\n", val_ptr->un.int_val );
          }
          break;
      case ovwBooleanField:
          printf( "%s\n",
             val_ptr->un.bool_val ? "TRUE" : "FALSE" );
          break;
      case ovwEnumField:
          printf( "%s\n", OVwDbGetFieldEnumByName(OID, FldID));
          break;
      default:
          fprintf (stderr, "Unable to convert field type %d\n", Type);
          exit (1);
   }
   exit (0);
}

int usage(char *Progname)
{
    fprintf(stderr, "usage: %s {-s <Selection Name>|-o <Object ID>}  {-f <Field 
Name>|-i <Field ID>} [-d]\n", Progname);
    fprintf(stderr, "\t-d: send debug info to stderr\n");
    exit(1);
}
<Prev in Thread] Current Thread [Next in Thread>

Archive operated by Skills 1st Ltd

See also: The NetView Web