LCOV - code coverage report
Current view: top level - src - main.c (source / functions) Hit Total Coverage
Test: mkernel.info Lines: 16 95 16.8 %
Date: 2024-11-11 22:28:11 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /**
       2             :  *    @file  main.c
       3             :  *   @brief
       4             :  *
       5             :  *  <+DETAILED+>
       6             :  *
       7             :  *  @author  François Cerbelle (Fanfan), francois@cerbelle.net
       8             :  *
       9             :  *  @internal
      10             :  *       Created:  25/10/2024
      11             :  *      Revision:  none
      12             :  * Last modified:  2024-11-10 15:25
      13             :  *      Compiler:  gcc
      14             :  *  Organization:  Cerbelle.net
      15             :  *     Copyright:  Copyright (c) 2024, François Cerbelle
      16             :  *
      17             :  *  This source code is released for free distribution under the terms of the
      18             :  *  GNU General Public License as published by the Free Software Foundation.
      19             :  */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include "config.h"
      23             : #endif
      24             : 
      25             : #include "ansi-color-codes.h"
      26             : #include "revision.h"
      27             : #include "csv.h"                                /* CSV manipulation functions */
      28             : #include "clusterlst.h"                         /* Cluster list structure */
      29             : #ifndef NOCPPCHECK
      30             : #include "rsstats-opts.h"                       /* Libopts generated options */
      31             : #endif
      32             : #include "rptbdbs.h"
      33             : #include "rptcluster.h"
      34             : 
      35             : #include <stdlib.h>
      36             : #include <string.h>
      37             : 
      38           7 : int main (int argc, char** argv, char** env) {
      39             :     FILE *reportfile;
      40             :     FILE *configfile;
      41             :     char  configline[1024];
      42             :     cluster_t* cluster;
      43             : 
      44             :     (void)env;                                  /* Avoid unused warning/error */
      45           7 :     printf(BCYN PACKAGE_NAME " " PACKAGE_VERSION RESET "\n");
      46             : #ifdef REVISION
      47           7 :     printf("Revision " BBLU REVISION RESET);
      48             : #endif
      49             : #ifdef BBID
      50           7 :     printf(" Build #" BBID);
      51             : #endif
      52           7 :     printf("\n");
      53             : 
      54             : #pragma GCC diagnostic push                             /* save the actual diag context */
      55             : #pragma GCC diagnostic ignored "-Wdate-time"         /* locally disable warnings because of non reproductible build triggered by pbuild */
      56           7 :     printf("Compiled %s at %s\n",__DATE__, __TIME__);
      57             : #pragma GCC diagnostic pop                              /* restore previous diag context */
      58           7 :     printf("Copyright 2024 François Cerbelle\n");
      59           7 :     printf("Report bugs to %s\n\n", BYEL PACKAGE_BUGREPORT RESET);
      60             :     /* AutoGen option parsing and consumming */
      61             :     {
      62           7 :         int arg_ct = optionProcess( &rsstatsOptions, argc, argv );
      63           1 :         argc -= arg_ct;
      64           1 :         argv += arg_ct;
      65             :     }
      66             : 
      67           1 :     printf("==> Read input file (cluster definitions): %s\n",OPT_ARG(INPUT));
      68             :     /* Open the cluster definitions files */
      69           1 :     configfile = fopen(OPT_ARG(INPUT), "r");
      70           1 :     if (!configfile) {
      71           1 :         perror("main open(configfile)");
      72           1 :         exit(EXIT_FAILURE);
      73             :     }
      74             : 
      75           0 :     unsigned int lineno = 0;
      76           0 :     while (fgets(configline, sizeof(configline), configfile) != NULL) {
      77           0 :         lineno++;
      78             : 
      79             :         /* Allocate a cluster record */
      80           0 :         if(NULL==(cluster=malloc(sizeof(struct cluster_s)))) {
      81           0 :             perror("main malloc(cluster)");
      82           0 :             exit(EXIT_FAILURE);
      83             :         }
      84             : 
      85             :         /* Extract cluster information from the configline */
      86           0 :         if (NULL==(cluster->host = csvtok(configline))) {
      87           0 :             fprintf(stderr,"Bad configline (%s:%ud)\n", OPT_ARG(INPUT), lineno);
      88           0 :             free(cluster);
      89           0 :             continue;
      90             :         }
      91           0 :         if (NULL==(cluster->user = csvtok(NULL))) {
      92           0 :             fprintf(stderr,"Bad configline (%s:%ud)\n", OPT_ARG(INPUT), lineno);
      93           0 :             free(cluster->host);
      94           0 :             free(cluster);
      95           0 :             continue;
      96             :         }
      97           0 :         if (NULL==(cluster->pass = csvtok(NULL))) {
      98           0 :             fprintf(stderr,"Bad configline (%s:%ud)\n", OPT_ARG(INPUT), lineno);
      99           0 :             free(cluster->host);
     100           0 :             free(cluster->user);
     101           0 :             free(cluster);
     102           0 :             continue;
     103             :         }
     104           0 :         if (NULL==(cluster->insecure = csvtok(NULL))) {
     105           0 :             fprintf(stderr,"Bad configline (%s:%ud)\n", OPT_ARG(INPUT), lineno);
     106           0 :             free(cluster->host);
     107           0 :             free(cluster->user);
     108           0 :             free(cluster->pass);
     109           0 :             free(cluster);
     110           0 :             continue;
     111             :         }
     112           0 :         if (NULL==(cluster->cacert = csvtok(NULL))) {
     113           0 :             fprintf(stderr,"Bad configline (%s:%ud)\n", OPT_ARG(INPUT), lineno);
     114           0 :             free(cluster->host);
     115           0 :             free(cluster->user);
     116           0 :             free(cluster->pass);
     117           0 :             free(cluster->insecure);
     118           0 :             free(cluster);
     119           0 :             continue;
     120             :         }
     121             : 
     122             :         /* Check if the configline should be processed */
     123           0 :         if ((NULL!=strstr(OPT_ARG(CLUSTERS),"all"))
     124           0 :                 ||(NULL!=strstr(OPT_ARG(CLUSTERS),cluster->host)))
     125           0 :             cluster->enabled=1;
     126             :         else
     127           0 :             cluster->enabled=0;
     128           0 :         if (clusterlist_find(cluster->host))
     129           0 :             fprintf(stderr,"Double cluster definition (%s @ %s:%ud)\n",
     130           0 :                     cluster->host, OPT_ARG(INPUT), lineno);
     131           0 :         clusterlist_add(cluster);
     132             :     }
     133           0 :     fclose(configfile);
     134             : 
     135           0 :     printf("==> Clusters to query : ");
     136           0 :     cluster=clusterlist_first();
     137           0 :     while(cluster) {
     138           0 :         if (cluster->enabled==1)
     139           0 :             printf("%s ",cluster->host);
     140           0 :         cluster = clusterlist_next();
     141             :     }
     142           0 :     printf("\n");
     143             : 
     144           0 :     printf("==> Open output file (report): %s\n",OPT_ARG(OUTPUT));
     145             : 
     146             :     /* Open the output file */
     147           0 :     reportfile = fopen(OPT_ARG(OUTPUT),"w");
     148           0 :     if (!reportfile) {
     149           0 :         perror("Opening output file");
     150           0 :         exit(EXIT_FAILURE);
     151             :     }
     152             : 
     153             :     /* Execute cluster report ? all or cluster specified */
     154           0 :     if (OPT_VALUE_REPORTS & REPORTS_CLUSTER) {
     155           0 :         printf("==> Running reports (cluster)\n");
     156           0 :         fprintf(reportfile,"\nclusters:\n");
     157           0 :         report_cluster_header(reportfile);
     158             :         /* Execute report against enabled clusters */
     159           0 :         cluster=clusterlist_first();
     160           0 :         while(cluster) {
     161             :             /* Check if the configline should be processed */
     162           0 :             if (cluster->enabled==1) {
     163           0 :                 printf("==> Running report (clusters) on cluster %s\n",cluster->host);
     164           0 :                 report_cluster(reportfile, cluster);
     165             :             }
     166           0 :             cluster = clusterlist_next();
     167             :         }
     168             :     }
     169             : 
     170             :     /* Execute bdbs report ? all or bdbs specified */
     171           0 :     if (OPT_VALUE_REPORTS & REPORTS_BDBS) {
     172           0 :         printf("==> Running reports (bdbs)\n");
     173           0 :         fprintf(reportfile,"\nbdbs:\n");
     174           0 :         report_bdbs_header(reportfile);
     175             :         /* Execute report against enabled clusters */
     176           0 :         cluster=clusterlist_first();
     177           0 :         while(cluster) {
     178             :             /* Check if the configline should be processed */
     179           0 :             if (cluster->enabled==1) {
     180           0 :                 printf("==> Running report (bdbs) on cluster %s\n",cluster->host);
     181           0 :                 report_bdbs(reportfile, cluster);
     182             :             }
     183           0 :             cluster = clusterlist_next();
     184             :         }
     185             :     }
     186             : 
     187           0 :     fclose(reportfile);
     188             : 
     189             : #ifdef _WIN32
     190             :     system("PAUSE");  /* For windows console window to wait. */
     191             : #endif
     192             : 
     193           0 :     return EXIT_SUCCESS;
     194             : }
     195             : /* vim: set tw=80: */

Generated by: LCOV version 1.16