コード例 #1
0
static void init()
{
  if (client==NULL && arg_mondemand_host!=NULL && arg_mondemand_ip!=NULL)
    {
      struct mondemand_transport *transport = NULL;
      client = mondemand_client_create("lwes-journaller");
      mondemand_set_context(client,"host",arg_mondemand_host);
      transport = mondemand_transport_lwes_create(arg_mondemand_ip,arg_mondemand_port,NULL,0,0);
      if (transport)
        {
          mondemand_add_transport(client, transport);
        }
      else
        {
          LOG_WARN("Unable to create mondemand transport to connect to %s:%d",arg_mondemand_ip,arg_mondemand_port);
        }
    }
}
コード例 #2
0
ファイル: mondemand-tool.c プロジェクト: mondemand/mondemand
int main (int   argc,
          char *argv[])
{
  const char *prog_id = "mondemand-tool";
  const char *args = "p:T:o:c:l:s:t:X:x:A:a:h";

  struct mondemand_client *client = NULL;
  struct mondemand_transport *transport = NULL;

  int stat_count = 0;
  int stat_error = 0;
  int log_count = 0;
  int trace_initialized = 0;
  int transport_count = 0;
  int perf_count = 0;

  int performance_trace_initialized = 0;

  unsigned short annotation_count = 0;
  unsigned short annotation_text_count = 0;
  char *annotation_text = NULL;

  int ret = 0;

  /* turn off error messages, I'll handle them */
  opterr = 0;

  /* get the program id */
  while (1)
    {
      char c = getopt (argc, argv, args);

      if (c == -1)
        {
          break;
        }
      switch (c)
        {
          case 'p':
            prog_id = optarg;
            break;

          case 'a':
            /* capture a count so we can error if there are too many */
            annotation_count++;
            break;

          case 'A':
            annotation_text = optarg;
            /* capture a count so we can error if there are too many */
            annotation_text_count++;
            break;

          /* deal with these below */
          case 'T':
          case 'o':
          case 'c':
          case 'l':
          case 's':
          case 't':
          case 'X':
          case 'x':
            break;

          case 'h':
            fprintf (stderr, "%s", help);
            return 1;

          default:
            fprintf (stderr,
                     "WARNING: unrecognized command line option -%c\n",
                     optopt);
        }
    }
  if (annotation_count > 1)
    {
      fprintf (stderr,
               "ERROR: can't specify '-a' more than once\n");
      exit (1);
    }
  if (annotation_text_count > 1)
    {
      fprintf (stderr,
               "ERROR: can't specify '-A' more than once\n");
      exit (1);
    }

  /* create the client */
  client = mondemand_client_create (prog_id);
  assert (client != NULL);

  /* have it keep all the messages */
  mondemand_set_no_send_level (client, M_LOG_ALL);
  mondemand_set_immediate_send_level (client, M_LOG_EMERG);

  /* reset the args list and go through them to get transports and trace meta
   * info
   */
  optind = 1;
  while (1)
    {
      char c = getopt (argc, argv, args);

      if (c == -1)
        {
          break;
        }

      switch (c)
        {
          case 'p':
            break;

          case 'X':
            if ((ret = initialize_perf_arg (optarg, client)) != 0)
              {
                fprintf (stderr, "ERROR: error initializing perf trace\n");
                goto cleanup;
              }
            performance_trace_initialized = 1;
            break;

          case 'T':
            if ((ret = initialize_trace_arg (optarg, client)) != 0)
              {
                fprintf (stderr, "ERROR: error initializing trace\n");
                goto cleanup;
              }
            trace_initialized = 1;
            break;

          case 'o':
            transport = handle_transport_arg (optarg);
            if ((ret = mondemand_add_transport (client, transport)) != 0)
              {
                fprintf (stderr, "WARNING: unable to add transport %s\n", optarg);
              }
            else
              {
                transport_count++;
              }
            break;

          case 'c':
          case 'l':
          case 's':
          case 't':
          case 'h':
          case 'x':
          case 'A':
          case 'a':
            break;

          default:
            break;
        }
    }
  if (transport_count == 0)
    {
      fprintf (stderr, "ERROR: must specify at least one transport with '-o'\n");
      ret = 1;
      goto cleanup;
    }

  /* reset again and get contexts */
  optind = 1;
  while (1)
    {
      char c = getopt (argc, argv, args);

      if (c == -1)
        {
          break;
        }

      switch (c)
        {
          case 'p':
          case 'T':
          case 'o':
            break;

          case 'c':
            if (handle_context_arg (optarg, client) < 0)
              {
                fprintf (stderr,
                         "WARNING: parsing of context %s failed\n", optarg);
              }
            break;

          case 'l':
          case 's':
          case 't':
          case 'h':
          case 'X':
          case 'x':
          case 'A':
          case 'a':
            break;

          default:
            break;
        }
    }

  /* finally get messages, statistics, and traces */
  optind = 1;
  while (1)
    {
      char c = getopt (argc, argv, args);

      if (c == -1)
        {
          break;
        }

      switch (c)
        {
          /* taken care of above */
          case 'p':
          case 'T':
          case 'o':
          case 'c':
            break;

          case 'l':
            if (handle_log_arg (optarg, client, log_count) == 0)
              {
                log_count++;
              }
            break;

          case 's':
            if (handle_stat_arg (optarg, client, stat_count) == 0)
              {
                stat_count++;
              }
            else
              {
                stat_error++;
              }
            break;

          case 't':
            if (trace_initialized)
              {
                ret = handle_trace_arg (optarg, client);
              }
            else
              {
                fprintf (stderr, "ERROR: can't specify '-t' without '-T'\n"
                                 "       ignoring argument\n");
                ret = 1;
              }
            break;

          case 'X':
            break;

          case 'x':
            if (performance_trace_initialized)
              {
                if ((ret = handle_perf_arg (optarg, client)) != 0)
                  {
                    fprintf (stderr, "ERROR: issue with '-x' arg %s\n",optarg);
                    goto cleanup;
                  }
                perf_count++;
              }
            else
              {
                fprintf (stderr, "ERROR: can't specify '-x' without '-X'\n"
                                 "       ignoring argument\n");
                ret = 1;
              }
            break;

          case 'A':
            break;

          case 'a':
            ret = handle_annotation_arg (optarg, annotation_text, client);
            break;

          case 'h':
            break;

          default:
            break;
        }
    }
  if (performance_trace_initialized && perf_count == 0)
    {
      fprintf (stderr, "ERROR: perf trace started with '-X' but not sent as"
                       " no '-x' was given\n");
      ret = 1;
    }
  if (stat_error > 0)
    {
      fprintf (stderr, "ERROR: had issues sending some stats\n");
      ret = 1;
    }

cleanup:
  mondemand_client_destroy (client);

  return ret;
}