]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
exporter: argument parsing
authorPere Diaz Bou <pdiazbou@redhat.com>
Thu, 5 May 2022 17:09:02 +0000 (19:09 +0200)
committerAvan Thakkar <athakkar@redhat.com>
Mon, 20 Jun 2022 18:24:54 +0000 (23:54 +0530)
Signed-off-by: Pere Diaz Bou <pdiazbou@redhat.com>
src/exporter/ceph_exporter.cc
src/exporter/http_server.cc
src/exporter/http_server.h

index 3122a9ca45a76ab163fbd909b184b2f1509a9bf5..4cf64ef4e7d674fee02c6575a23060eb9c7a9eca 100644 (file)
@@ -1,14 +1,53 @@
+#include "common/ceph_argparse.h"
 #include "exporter/DaemonMetricCollector.h"
 #include "exporter/http_server.h"
+#include <boost/thread/thread.hpp>
 #include <iostream>
 #include <map>
-#include <iostream>
 #include <string>
-#include <boost/thread/thread.hpp>
 
+static void usage() {
+  std::cout << "usage: ceph-exporter --cert cert.pem --key cert.key "
+               "--tls_options no[flags]\n"
+            << "--cert: TLS/SSL certificate in pem format\n"
+            << "--key: TLS/SSL key in pem format\n"
+            << "--tls_options: colon separated options for tls and ssl.\n"
+            << "\tExample -> "
+               "default_workarounds:no_compression:no_sslv2:no_sslv3:no_tlsv1:"
+               "no_tlsv1_1:no_tlsv1_2:single_dh_use\n"
+            << std::endl;
+  generic_server_usage();
+}
+
+int main(int argc, char **argv) {
+
+  auto args = argv_to_vec(argc, argv);
+  if (args.empty()) {
+    std::cerr << argv[0] << ": -h or --help for usage" << std::endl;
+    exit(1);
+  }
+  if (ceph_argparse_need_usage(args)) {
+    usage();
+    exit(0);
+  }
+  std::string val, cert_path, key_path, tls_options;
+  for (auto i = args.begin(); i != args.end();) {
+    if (ceph_argparse_witharg(args, i, &val, "--cert", (char *)NULL)) {
+      cert_path = val;
+    } else if (ceph_argparse_witharg(args, i, &val, "--key", (char *)NULL)) {
+      key_path = val;
+    } else if (ceph_argparse_witharg(args, i, &val, "--tls_options",
+                                     (char *)NULL)) {
+      tls_options = val;
+    } else if (ceph_argparse_flag(args, i, "--help", (char *)NULL) ||
+               ceph_argparse_flag(args, i, "-h", (char *)NULL)) {
+      usage();
+      exit(0);
+    }
+  }
 
-int main(int argc, char** argv) {
-  boost::thread server_thread(http_server_thread_entrypoint);
+  boost::thread server_thread(http_server_thread_entrypoint, cert_path,
+                              key_path, tls_options);
   DaemonMetricCollector &collector = collector_instance();
   collector.main();
   server_thread.join();
index cb9a72104bed3a567520e92c6592d5674f3de9e5..5cd153e33c1c1e8451e1245f7ca223059436475e 100644 (file)
@@ -145,7 +145,8 @@ std::string dns_lookup(std::string hostname) {
   return ip_address;
 }
 
-void http_server_thread_entrypoint() {
+void http_server_thread_entrypoint(std::string cert_path, std::string key_path,
+                                   std::string tls_options) {
   try {
     std::string hostname = ceph_get_short_hostname();
 
index 55e61904a9f4ca1c72679ff2bc0198b71ad875bb..368932ae03a54908b46f493f86ef9b89e99379b5 100644 (file)
@@ -1,3 +1,5 @@
 #pragma once
 
-void http_server_thread_entrypoint();
+#include <string>
+
+void http_server_thread_entrypoint(std::string cert_path, std::string key_path, std::string tls_options);