AFS-Monitor

 view release on metacpan or  search on metacpan

src/Monitor.xs  view on Meta::CPAN

                || SvTYPE(GROUP = (HV *) SvRV(GROUP)) != SVt_PVHV) {
               continue;
            }
            if (type == FS)
               varName = fs_varNames[idx];
            else if (type == CM)
               varName = cm_varNames[idx];
            else
               return (-1);

            if (hv_exists(GROUP, varName, strlen(varName))) {
               VALUE = (HV *)
                  SvRV(*hv_fetch(GROUP, varName, strlen(varName), FALSE));
               pValue = SvIV(*hv_fetch(VALUE, "value", 5, FALSE));
               found = 1;
               break;
            }
         }
         if (found)
            break;
      }

      if (!found) {
         threshP++;
         continue;
      }

      if (pValue > tValue) {
         hv_store(VALUE, "overflow", 8, newSViv(1), 0);
         hv_store(VALUE, "threshold", 9, newSVnv(tValue), 0);

         if (threshP->handler[0] != '\0') {
            sprintf(strval, "%g", pValue);
            code = my_execute_thresh_handler(threshP->handler,
                                             a_hostEntry->hostName, type,
                                             threshP->itemName,
                                             threshP->threshVal, strval,
                                             VALUE, buffer);
            if (code) {
               return (code);
            }
         }

         count++;
      }
      threshP++;
   }

   return (0);
}   /* my_check_thresholds() */




/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_process_config_file(a_config_filename, numFS, numCM, lastHostType,
                       last_hostEntry, fs_showDefault, cm_showDefault,
                       fs_showFlags, cm_showFlags, FSnameList, CMnameList)
   char *a_config_filename;
   int *numFS;
   int *numCM;
   int *lastHostType;
   struct afsmon_hostEntry **last_hostEntry;
   int *fs_showDefault;
   int *cm_showDefault;
   short *fs_showFlags;
   short *cm_showFlags;
   struct afsmon_hostEntry **FSnameList;
   struct afsmon_hostEntry **CMnameList;
{
   char buff1[256] = "";        /* for error messages */
   char buff2[256] = "";        /* for error messages returned from subroutines */
   FILE *configFD = 0;          /* config file descriptor */
   char line[4 * CFG_STR_LEN];  /* a line of config file */
   char opcode[CFG_STR_LEN];    /* specifies type of config entry */
   char arg1[CFG_STR_LEN];      /* hostname or qualifier (fs/cm?)  */
   char arg2[CFG_STR_LEN];      /* threshold variable */
   char arg3[CFG_STR_LEN];      /* threshold value */
   char arg4[CFG_STR_LEN];      /* user's handler  */
   struct afsmon_hostEntry *curr_host = 0;
   struct hostent *he = 0;      /* hostentry to resolve host name */
   char *handlerPtr = 0;        /* ptr to pass theresh handler string */
   int code = 0;                /* error code */
   int linenum = 0;             /* config file line number */
   int threshCount = 0;         /* count of thresholds for each server */
   int error_in_config = 0;     /* syntax errors in config file  ?? */
   int i = 0;
   int numBytes = 0;
   /* int global_ThreshFlag = 1; */
   int global_fsThreshCount = 0;
   int global_cmThreshCount = 0;
   static char last_fsHost[HOST_NAME_LEN];
   static char last_cmHost[HOST_NAME_LEN];

   /* open config file */
   configFD = fopen(a_config_filename, "r");
   if (configFD == (FILE *) NULL) {
      sprintf(buff1, "Failed to open config file %s", a_config_filename);
      BSETCODE(5, buff1);
      return (-1);
   }

   /* parse config file */

   /* First Pass - check syntax and count number of servers and thresholds to monitor */

   *numFS = 0;
   *numCM = 0;
   threshCount = 0;
   error_in_config = 0; /* flag to note if config file has syntax errors */

   while ((fgets(line, CFG_STR_LEN, configFD)) != NULL) {
      opcode[0] = 0;
      arg1[0] = 0;
      arg2[0] = 0;
      arg3[0] = 0;
      arg4[0] = 0;
      sscanf(line, "%s %s %s %s %s", opcode, arg1, arg2, arg3, arg4);
      linenum++;
      /* fprintf(STDERR, "Got line %d: \"%s %s %s %s %s\"\n",
       * linenum, opcode, arg1, arg2, arg3, arg4); */
      /* skip blank lines and comment lines */
      if ((strlen(opcode) == 0) || line[0] == '#') {
         /* fprintf(STDERR, " - skipping line %d\n", linenum); */
         continue;
      }
      if ((strcasecmp(opcode, "fs") == 0) || (strcasecmp(opcode, "cm")) == 0) {
         /* fprintf(STDERR, " - parsing host entry\n"); */
         code =
            my_parse_hostEntry(line, numFS, numCM, lastHostType,
                               last_hostEntry, FSnameList, CMnameList, buff2);
         /* thresholds are not global anymore */
         /* if (global_ThreshFlag) global_ThreshFlag = 0; */
      }
      else if ((strcasecmp(opcode, "thresh")) == 0) {
         /* fprintf(STDERR, " - parsing thresh entry\n"); */
         code =
            my_parse_threshEntry(line, &global_fsThreshCount,
                                 &global_cmThreshCount, *last_hostEntry,
                                 *lastHostType, buff2);
      }
      else if ((strcasecmp(opcode, "show")) == 0) {
         /* fprintf(STDERR, " - parsing show entry\n"); */
         code =
            my_parse_showEntry(line, fs_showDefault, cm_showDefault,
                               fs_showFlags, cm_showFlags, buff2);
      }
      else {
         /* fprintf(STDERR, " - unknown entry\n"); */
         sprintf(buff2, "Unknown opcode %s", opcode);
         code = 1;
      }

      if (code) {
         sprintf(buff1,
                 "Error processing config file line %d (\"%s %s %s %s %s\"). %s",
                 linenum, opcode, arg1, arg2, arg3, arg4, buff2);
         error_in_config = 1;
         BSETCODE(10, buff1);
         return (-1);
      }
   }
   /* fprintf(STDERR, "got to end of file.\n"); */

   if (error_in_config) {
      sprintf(buff1, "Error in config file. %s", buff2);
      BSETCODE(10, buff1);
      return (-1);
   }

   /* the threshold count of all hosts in increased by 1 for each global
    * threshold. If one of the hosts has a local threshold for the same
    * variable it would end up being counted twice. whats a few bytes of memory
    * wasted anyway ? */

   if (global_fsThreshCount) {
      curr_host = *FSnameList;
      for (i = 0; i < *numFS; i++) {
         curr_host->numThresh += global_fsThreshCount;
         curr_host = curr_host->next;
      }
   }
   if (global_cmThreshCount) {
      curr_host = *CMnameList;
      for (i = 0; i < *numCM; i++) {
         curr_host->numThresh += global_cmThreshCount;
         curr_host = curr_host->next;
      }
   }

   /* make sure we have something to monitor */
   if (*numFS == 0 && *numCM == 0) {
      sprintf(buff1,
              "Config file must specify atleast one File Server or Cache Manager host to monitor.");
      fclose(configFD);
      BSETCODE(15, buff1);
      return (-1);
   }

   /* Second Pass */

   fseek(configFD, 0, 0);   /* seek to the beginning */

   /* allocate memory for threshold lists */

   curr_host = *FSnameList;
   for (i = 0; i < *numFS; i++) {
      if (curr_host->hostName[0] == '\0') {
         sprintf(buff1, "Programming error 4");
         BSETCODE(20, buff1);
         return (-1);
      }
      if (curr_host->numThresh) {
         numBytes = curr_host->numThresh * sizeof(struct Threshold);
         curr_host->thresh = (struct Threshold *)malloc(numBytes);
         if (curr_host->thresh == (struct Threshold *) NULL) {

src/Monitor.xs  view on Meta::CPAN

   linenum = 0;
   while ((fgets(line, CFG_STR_LEN, configFD)) != NULL) {
      opcode[0] = 0;
      arg1[0] = 0;
      arg2[0] = 0;
      arg3[0] = 0;
      arg4[0] = 0;
      sscanf(line, "%s %s %s %s %s", opcode, arg1, arg2, arg3, arg4);
      linenum++;

      /* if we have a host entry, remember the host name */
      if (strcasecmp(opcode, "fs") == 0) {
         he = GetHostByName(arg1);
         strncpy(last_fsHost, he->h_name, HOST_NAME_LEN);
      }
      else if (strcasecmp(opcode, "cm") == 0) {
         he = GetHostByName(arg1);
         strncpy(last_cmHost, he->h_name, HOST_NAME_LEN);
      }
      else if (strcasecmp(opcode, "thresh") == 0) {
         /* if we have a threshold handler it may have arguments
          * and the sscanf() above would not get them, so do the
          * following */
         if (strlen(arg4)) {
            handlerPtr = line;
            /* now skip over 4 words - this is done by first
             * skipping leading blanks then skipping a word */
            for (i = 0; i < 4; i++) {
               while (isspace(*handlerPtr))
                  handlerPtr++;
               while (!isspace(*handlerPtr))
                  handlerPtr++;
            }
            while (isspace(*handlerPtr))
               handlerPtr++;
            /* we how have a pointer to the start of the handler
             * name & args */
         }
         else
            handlerPtr = arg4;  /* empty string */

         if (strcasecmp(arg1, "fs") == 0)
            code = my_store_threshold(1,    /* 1 = fs */
                                      arg2, arg3, handlerPtr,
                                      &global_fsThreshCount, *FSnameList,
                                      last_fsHost, *numFS, buff2);

         else if (strcasecmp(arg1, "cm") == 0)
            code = my_store_threshold(2,    /* 2 = cm */
                                      arg2, arg3, handlerPtr,
                                      &global_cmThreshCount, *CMnameList,
                                      last_cmHost, *numCM, buff2);

         else {
            sprintf(buff1, "Programming error 6");
            BSETCODE(40, buff1);
            return (-1);
         }
         if (code) {
            sprintf(buff1,
                    "Error processing config file line %d (\"%s %s %s %s %s\"): Failed to store threshold. %s",
                    linenum, opcode, arg1, arg2, arg3, arg4, buff2);
            BSETCODE(45, buff1);
            return (-1);
         }
      }
   }

   fclose(configFD);
   return (0);
}   /* my_process_config_file() */




/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_OpTiming(a_opIdx, a_opTimeP, fs_outFD)
   int a_opIdx;
   struct fs_stats_opTimingData *a_opTimeP;
   FILE *fs_outFD;
{

   fprintf(fs_outFD,
           "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           fsOpNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
           a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
           a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
           a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
}   /* my_Print_fs_OpTiming() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_XferTiming(a_opIdx, a_xferP, fs_outFD)
   int a_opIdx;
   struct fs_stats_xferData *a_xferP;
   FILE *fs_outFD;
{

   fprintf(fs_outFD,
           "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           xferOpNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
           a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
           a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
           a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
   fprintf(fs_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n",
           a_xferP->sumBytes, a_xferP->minBytes, a_xferP->maxBytes);
   fprintf(fs_outFD,
           "\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
           a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
           a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
           a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);
}   /* my_Print_fs_XferTiming() */



/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void

src/Monitor.xs  view on Meta::CPAN


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_XListPartitions(aconn, ptrPartList, cntp, scout_debugfd)
   struct rx_connection *aconn;
   struct partList *ptrPartList;
   afs_int32 *cntp;
   FILE *scout_debugfd;
{
   struct pIDs partIds;
   struct partEntries partEnts;
   register int i, j = 0, code;
   static int newvolserver = 0;

   static char rn[] = "my_XListPartitions";
   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }

   *cntp = 0;
   if (newvolserver == 1) {
      for (i = 0; i < 26; i++)
         partIds.partIds[i] = -1;
    tryold:
      code = AFSVolListPartitions(aconn, &partIds);
      if (!code) {
         for (i = 0; i < 26; i++) {
            if ((partIds.partIds[i]) != -1) {
               ptrPartList->partId[j] = partIds.partIds[i];
               ptrPartList->partFlags[j] = PARTVALID;
               j++;
            }
            else
               ptrPartList->partFlags[i] = 0;
         }
         *cntp = j;
      }
      goto out;
   }
   partEnts.partEntries_len = 0;
   partEnts.partEntries_val = (afs_int32 *) NULL;
   code = AFSVolXListPartitions(aconn, &partEnts);
   if (!newvolserver) {
      if (code == RXGEN_OPCODE) {
         newvolserver = 1;  /* Doesn't support new interface */
         goto tryold;
      }
      else if (!code) {
         newvolserver = 2;
      }
   }
   if (!code) {
      *cntp = partEnts.partEntries_len;
      if (*cntp > VOLMAXPARTS) {
         warn
            ("Warning: number of partitions on the server too high %d (process only %d)\n",
             *cntp, VOLMAXPARTS);
         *cntp = VOLMAXPARTS;
      }
      for (i = 0; i < *cntp; i++) {
         ptrPartList->partId[i] = partEnts.partEntries_val[i];
         ptrPartList->partFlags[i] = PARTVALID;
      }
      free(partEnts.partEntries_val);
   }
 out:
   if (code)
      warn("Could not fetch the list of partitions from the server\n");
   return code;
}


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_fsprobe_Cleanup(fsprobe_Results, fsprobe_ConnInfo, fsprobe_numServers,
                   scout_debugfd, buffer)
   struct fsprobe_ProbeResults *fsprobe_Results;
   struct fsprobe_ConnectionInfo *fsprobe_ConnInfo;
   int fsprobe_numServers;
   FILE *scout_debugfd;
   char *buffer;
{

   int code = 0;                /*Return code */
   int conn_idx;                /*Current connection index */
   struct fsprobe_ConnectionInfo *curr_conn;    /*Ptr to fsprobe connection */
   static char rn[] = "my_fsprobe_Cleanup";

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }


   /*
    * Take care of all Rx connections first.  Check to see that the
    * server count is a legal value.
    */
   if (fsprobe_numServers <= 0) {
      sprintf(buffer,
              "[%s] Illegal number of servers to clean up (fsprobe_numServers = %d)",
              rn, fsprobe_numServers);
      code = -1;
   }
   else {
      if (fsprobe_ConnInfo != (struct fsprobe_ConnectionInfo *) NULL) {
         /*
          * The fsprobe connection structure array exists.  Go through it
          * and close up any Rx connections it holds.
          */
         curr_conn = fsprobe_ConnInfo;
         for (conn_idx = 0; conn_idx < fsprobe_numServers; conn_idx++) {

src/Monitor.xs  view on Meta::CPAN

  {
    I32 keylen = 0;
    char* key = 0;
    SV* value = 0;
    char* host = 0;
    AV* host_array = 0;
    AV* show_array = 0;
    AV* fsthresh_array = 0;
    AV* cmthresh_array = 0;
    HV* thresh_entry = 0;
    int global_fsThreshCount = 0;
    int global_cmThreshCount = 0;
    int found = 0;
    int numBytes = 0;
    char* thresh_name = "";
    char* thresh_value = 0;
    char* thresh_host = "";
    char* thresh_handler = "";
    int num_args = 0;
    int detailed = 0;
    char* config_filename = 0;
    char* output_filename = 0;
    FILE *outputFD = 0;
    struct afsmon_hostEntry *temp_host = 0;
    int numFS = 0;
    int numCM = 0;
    struct afsmon_hostEntry *last_hostEntry = 0;
    int lastHostType = 0;
    short fs_showFlags[NUM_FS_STAT_ENTRIES];
    short cm_showFlags[NUM_CM_STAT_ENTRIES];
    int fs_showDefault = 1;
    int cm_showDefault = 1;

    int num = 0;
    int i = 0;
    int j = 0;
    int code = 0;
    char buffer[256] = "";
    char buff2[256] = "";

    /* from afsmon_execute() */
    static char fullhostname[128] = "";   /* full host name */
    struct sockaddr_in *FSSktArray = 0;   /* fs socket array */
    int FSsktbytes = 0;         /* num bytes in above */
    struct sockaddr_in *CMSktArray = 0;   /* cm socket array */
    int CMsktbytes = 0;         /* num bytes in above */
    struct sockaddr_in *curr_skt = 0;     /* ptr to current socket*/
    struct afsmon_hostEntry *curr_FS = 0; /* ptr to FS name list */
    struct afsmon_hostEntry *curr_CM = 0; /* ptr to CM name list */
    struct hostent *he = 0;     /* host entry */
    afs_int32 *collIDP = 0;     /* ptr to collection ID */
    int numCollIDs = 0;         /* number of collection IDs */
    /* end of from afsmon_execute() */

    AV* FILESERV = newAV(); /* File Servers */
    AV* CACHEMAN = newAV(); /* Cache Managers */

    struct afsmon_hostEntry *FSnameList=0;
    struct afsmon_hostEntry *CMnameList=0;

    /* initialize showFlags for processing "show" directives in config file */
    for(i=0; i<NUM_FS_STAT_ENTRIES; i++)
      fs_showFlags[i] = 0;
    for(i=0; i<NUM_CM_STAT_ENTRIES; i++)
      cm_showFlags[i] = 0;

    /* parse arguments */
    num_args = hv_iterinit(args);
    /* fprintf(STDERR, "[afsmonitor] Parsing args now: %d\n", num_args); */
    while (num_args--) {
      value = hv_iternextsv(args, &key, &keylen);

      /* fprintf(STDERR, "got flag %s, size %d. %d remaining.\n", key, keylen, num_args); */

      switch (*key) {
        case 'c':
          if(keylen < 2) goto unrecognized;
          switch(key[1]) {
            case 'o':
              if(strncmp(key, "config", keylen) == 0 && keylen <= 6) {
                /* fprintf(STDERR, "flag %s recognized as config; value is %s\n",
                   key, (char *) SvPV(value, PL_na)); */
                config_filename = (char *) SvPV(value, PL_na);
              } else goto unrecognized;
            break;

            case 'm':
              if(keylen < 3) goto unrecognized;
              switch(key[2]) {
                case 'h':
                 if(strncmp(key, "cmhosts", keylen) == 0 && keylen <= 7) {
                   /* fprintf(STDERR, "flag %s recognized as cmhosts\n", key); */
                  if (SvROK(value))
                    host_array = (AV*) SvRV(value);
                  else {
                    host_array = av_make(1, &value);
                    sv_2mortal((SV *) host_array);
                  }
                   num = av_len(host_array);
                   /* fprintf(STDERR, "it has %d elements.\n", num+1); */
                   for(i=0; i<=num; i++) {
                     host = (char *) SvPV(*av_fetch(host_array, i, 0), PL_na);
                     sprintf(buffer,"cm %s",host);
                     code = my_parse_hostEntry(buffer, &numFS, &numCM, &lastHostType,
                                            &last_hostEntry, &FSnameList, &CMnameList, buff2);
                     /* fprintf(STDERR, "got host: %s\n", host); */
                     if (code) {
                       sprintf(buffer, "Could not parse cache manager %s. %s", host, buff2);
                       BSETCODE(180, buffer);
                       /* 180 is the exit code for this error in the original afsmonitor.c */
                       XSRETURN_UNDEF;
                     }
                   }
                 } else goto unrecognized;
                 break;
                case 's':
                 if(strncmp(key, "cmshow", keylen) == 0 && keylen <= 6) {
                   /* fprintf(STDERR, "flag %s recognized as cmshow\n", key); */
                   show_array = (AV*) SvRV(value);
                   num = av_len(show_array);
                   for (i=0; i<=num; i++) {

src/Monitor.xs  view on Meta::CPAN

        temp_host = CMnameList;
        for (i = 0; i < numCM; i++) {
          temp_host->numThresh += global_cmThreshCount;
          temp_host = temp_host->next;
        }
      }
      temp_host = CMnameList;
      for (i = 0; i < numCM; i++) {
        if (temp_host->numThresh) {
          numBytes = temp_host->numThresh * sizeof(struct Threshold);
          temp_host->thresh = (struct Threshold *)malloc(numBytes);
          if (temp_host->thresh == (struct Threshold *) NULL) {
            sprintf(buffer, "Memory Allocation error 2.5");
            BSETCODE(25, buffer);
            XSRETURN_UNDEF;
          }
          memset(temp_host->thresh, 0, numBytes);
        }
        temp_host = temp_host->next;
      }
      num = av_len(cmthresh_array);
      for (i=0; i<=num; i++) {
        thresh_host = 0;
        thresh_handler = "";
        thresh_entry = (HV*) SvRV(*av_fetch(cmthresh_array, i, 0));
        hv_iterinit(thresh_entry);
        while((value = hv_iternextsv(thresh_entry, &key, &keylen))) {
          if(strcmp(key, "host") == 0) {
            thresh_host = (char *)SvPV(value, PL_na);
            he = GetHostByName(thresh_host);
            if(he == (struct hostent *) NULL) {
              sprintf(buffer,
                      "Couldn't parse cmthresh flag; unable to resolve hostname %s\n",
                      thresh_host);
              BSETCODE(-1, buffer);
              XSRETURN_UNDEF;
            }
            thresh_host = he->h_name;
          }
          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        if(thresh_host) global_cmThreshCount = 0;
        else global_cmThreshCount = 1;
        code = my_store_threshold(2, thresh_name, thresh_value, thresh_handler,
                           &global_cmThreshCount, CMnameList, thresh_host,
                           numCM, buff2);
        if(code) {
          sprintf(buffer, "Unable to store threshold %s. %s", thresh_name, buff2);
          BSETCODE(code, buffer);
          XSRETURN_UNDEF;
        }
      }
    }

    /* process configuration file */
    if(config_filename) {
      code = my_process_config_file(config_filename, &numFS, &numCM, &lastHostType,
                                 &last_hostEntry, &fs_showDefault, &cm_showDefault,
                                 fs_showFlags, cm_showFlags, &FSnameList, &CMnameList);
      if(code == -1)
        XSRETURN_UNDEF;
    }

  /* from afsmon_execute() */

    /* process file server entries */
    if (numFS) {
    /* Allocate an array of sockets for each fileserver we monitor */

      FSsktbytes = numFS * sizeof(struct sockaddr_in);
      FSSktArray = (struct sockaddr_in *) malloc(FSsktbytes);
      if (FSSktArray == (struct sockaddr_in *) NULL) {
        sprintf(buffer,"cannot malloc %d sockaddr_ins for fileservers", numFS);
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }

      memset(FSSktArray, 0, FSsktbytes);

      /* Fill in the socket information for each fileserve  */

      curr_skt = FSSktArray;
      curr_FS = FSnameList;  /* FS name list header */
      while (curr_FS) {
        strncpy(fullhostname,curr_FS->hostName,sizeof(fullhostname));
        he = GetHostByName(fullhostname);
        if (he == (struct hostent *) NULL) {
          sprintf(buffer,"Cannot get host info for %s", fullhostname);
          BSETCODE(-1, buffer);
          XSRETURN_UNDEF;
        }
        strncpy(curr_FS->hostName,he->h_name,HOST_NAME_LEN); /* complete name*/
        memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
            curr_skt->sin_family = AF_INET;             /*Internet family */
#else
            curr_skt->sin_family = htons(AF_INET);      /*Internet family */
#endif
        curr_skt->sin_port   = htons(7000);       /*FileServer port*/
#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
        curr_skt->sin_len = sizeof(struct sockaddr_in);
#endif
        /* get the next dude */
        curr_skt++;
        curr_FS = curr_FS->next;
      }

      /* initialize collection IDs. We need only one entry since we collect
         all the information from xstat */

      numCollIDs = 1;
      collIDP = (afs_int32 *) malloc (sizeof (afs_int32));
      if (collIDP == (afs_int32 *) NULL) {
        sprintf(buffer,"failed to allocate a measely afs_int32 word. Argh!");
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      *collIDP = 2;     /* USE A macro for this */

      code = my_xstat_fs_Init(my_afsmon_FS_Handler, numFS, FSSktArray, numCollIDs,
                              collIDP, buff2, output_filename, detailed, FILESERV,
                              FSnameList, fs_showFlags, fs_showDefault);

      if (code) {
        sprintf(buffer,"my_xstat_fs_Init() returned error. %s", buff2);
        BSETCODE(125, buffer);
        XSRETURN_UNDEF;
      }
    }  /* end of process fileserver entries */

    /* process cache manager entries */
    if (numCM) {
    /* Allocate an array of sockets for each fileserver we monitor */

      CMsktbytes = numCM * sizeof(struct sockaddr_in);
      CMSktArray = (struct sockaddr_in *) malloc(CMsktbytes);
      if (CMSktArray == (struct sockaddr_in *) NULL) {
        sprintf(buffer,"cannot malloc %d sockaddr_ins for CM entries", numCM);
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }

      memset(CMSktArray, 0, CMsktbytes);

      /* Fill in the socket information for each CM  */

      curr_skt = CMSktArray;
      curr_CM = CMnameList;  /* CM name list header */
      while (curr_CM) {
        strncpy(fullhostname,curr_CM->hostName,sizeof(fullhostname));
        he = GetHostByName(fullhostname);
        if (he == (struct hostent *) NULL) {
          sprintf(buffer,"Cannot get host info for %s", fullhostname);
          BSETCODE(-1, buffer);
          XSRETURN_UNDEF;
        }
        strncpy(curr_CM->hostName,he->h_name,HOST_NAME_LEN); /* complete name*/
        memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
        curr_skt->sin_family = htons(AF_INET);    /*Internet family*/
        curr_skt->sin_port   = htons(7001);  /*Cache Manager port */
#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
        curr_skt->sin_len = sizeof(struct sockaddr_in);
#endif

        /* get the next dude */
        curr_skt++;
        curr_CM = curr_CM->next;
      }

      /* initialize collection IDs. We need only one entry since we collect
         all the information from xstat */

      numCollIDs = 1;
      collIDP = (afs_int32 *) malloc (sizeof (afs_int32));
      if (collIDP == (afs_int32 *) NULL) {
        sprintf(buffer,"failed to allocate a measely afs_int32 word. Argh!");
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      *collIDP = 2;     /* USE A macro for this */

      code = my_xstat_cm_Init(my_afsmon_CM_Handler, numCM, CMSktArray, numCollIDs,
                              collIDP, buff2, output_filename, detailed, CACHEMAN,
                              CMnameList, cm_showFlags, cm_showDefault);

      if (code) {
        sprintf(buffer,"my_xstat_cm_Init() returned error. %s", buff2);
        BSETCODE(130, buffer);
        XSRETURN_UNDEF;
      }

    }  /* end of process fileserver entries */

  /* end from afsmon_execute() */

    SETCODE(0);

    EXTEND(SP, 2);
    PUSHs(sv_2mortal(newRV_inc((SV*)FILESERV)));
    PUSHs(sv_2mortal(newRV_inc((SV*)CACHEMAN)));
  }


void
afs_do_rxdebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    int size;
    I32 keylen;
    char *key;
    HE* entry;
    SV* value;
    HV* RETVAL = newHV(); /* return value */
    HV* TSTATS;
    HV* RXSTATS;
    AV* CONNECTIONS;
    HV* TCONN;
    AV* CALLSTATE;
    AV* CALLMODE;
    AV* CALLFLAGS;
    AV* CALLOTHER;
    AV* CALLNUMBER;
    AV* PEERS;
    HV* TPEER;
    HV* BYTESSENT;
    HV* BYTESRECEIVED;
    HV* TIMEOUT;
    int index;

    register int i;
    int s;
    int j;
    struct sockaddr_in taddr;
    afs_int32 host;
    struct in_addr hostAddr;
    short port;
    struct hostent *th;
    register afs_int32 code;
    int nodally=0;
    int allconns=0;
    int rxstats=0;
    int onlyClient=0;
    int onlyServer=0;
    afs_int32 onlyHost = -1;
    short onlyPort = -1;
    int onlyAuth = 999;
    int flag;
    int dallyCounter;
    int withSecStats;
    int withAllConn;



( run in 0.787 second using v1.01-cache-2.11-cpan-39bf76dae61 )