587943
From bc60f9c84bd6f0fa4d73db8d140030dfcdbf4f5e Mon Sep 17 00:00:00 2001
587943
From: Chris Lumens <clumens@redhat.com>
587943
Date: Tue, 19 Jan 2021 15:58:36 -0500
587943
Subject: [PATCH 1/2] Fix: tools: Describe interactive crm_mon use in help and
587943
 man page.
587943
587943
---
587943
 tools/crm_mon.8.inc | 3 +++
587943
 tools/crm_mon.c     | 4 ++++
587943
 tools/fix-manpages  | 2 +-
587943
 3 files changed, 8 insertions(+), 1 deletion(-)
587943
587943
diff --git a/tools/crm_mon.8.inc b/tools/crm_mon.8.inc
587943
index e4cd7e3..6b46d7b 100644
587943
--- a/tools/crm_mon.8.inc
587943
+++ b/tools/crm_mon.8.inc
587943
@@ -12,3 +12,6 @@ crm_mon mode [options]
587943
 
587943
 /command line arguments./
587943
 .SH TIME SPECIFICATION
587943
+
587943
+/or --exclude=list./
587943
+.SH INTERACTIVE USE
587943
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
587943
index 083b7ae..aafc80f 100644
587943
--- a/tools/crm_mon.c
587943
+++ b/tools/crm_mon.c
587943
@@ -1062,6 +1062,10 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
587943
                               "times on the command line, and each can give a comma-separated list of sections.\n"
587943
                               "The options are applied to the default set, from left to right as seen on the\n"
587943
                               "command line.  For a list of valid sections, pass --include=list or --exclude=list.\n\n"
587943
+                              "Interactive Use:\n\n"
587943
+                              "When run interactively, crm_mon can be told to hide and display various sections\n"
587943
+                              "of output.  To see a help screen explaining the options, hit '?'.  Any key stroke\n"
587943
+                              "aside from those listed will cause the screen to refresh.\n\n"
587943
                               "Examples:\n\n"
587943
                               "Display the cluster status on the console with updates as they occur:\n\n"
587943
                               "\tcrm_mon\n\n"
587943
diff --git a/tools/fix-manpages b/tools/fix-manpages
587943
index 714ecce..f1f6f0d 100644
587943
--- a/tools/fix-manpages
587943
+++ b/tools/fix-manpages
587943
@@ -26,7 +26,7 @@
587943
 # This leaves the --help-all output looking good and removes redundant
587943
 # stuff from the man page.  Feel free to add additional headers here.
587943
 # Not all tools will have all headers.
587943
-/.SH NOTES\|.SH OPERATION SPECIFICATION\|.SH OUTPUT CONTROL\|.SH TIME SPECIFICATION/{ n
587943
+/.SH NOTES\|.SH INTERACTIVE USE\|.SH OPERATION SPECIFICATION\|.SH OUTPUT CONTROL\|.SH TIME SPECIFICATION/{ n
587943
 N
587943
 N
587943
 d
587943
-- 
587943
1.8.3.1
587943
587943
587943
From ed4e4370dc97bc220878db89d69c71426b9458a3 Mon Sep 17 00:00:00 2001
587943
From: Chris Lumens <clumens@redhat.com>
587943
Date: Tue, 19 Jan 2021 17:02:45 -0500
587943
Subject: [PATCH 2/2] Fix: tools: The 'm' key in crm_mon is a cycle, not a
587943
 toggle.
587943
587943
Each time it's pressed, a different amount of fencing information should
587943
be shown, cycling back to nothing after level 3.
587943
---
587943
 tools/crm_mon.c | 76 +++++++++++++++++++++++++++++++++++++++++----------------
587943
 1 file changed, 55 insertions(+), 21 deletions(-)
587943
587943
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
587943
index aafc80f..0981634 100644
587943
--- a/tools/crm_mon.c
587943
+++ b/tools/crm_mon.c
587943
@@ -83,6 +83,8 @@ static gchar **processed_args = NULL;
587943
 static time_t last_refresh = 0;
587943
 crm_trigger_t *refresh_trigger = NULL;
587943
 
587943
+int interactive_fence_level = 0;
587943
+
587943
 static pcmk__supported_format_t formats[] = {
587943
 #if CURSES_ENABLED
587943
     CRM_MON_SUPPORTED_FORMAT_CURSES,
587943
@@ -382,9 +384,9 @@ as_xml_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError *
587943
 
587943
 static gboolean
587943
 fence_history_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **err) {
587943
-    int rc = crm_atoi(optarg, "2");
587943
+    interactive_fence_level = crm_atoi(optarg, "2");
587943
 
587943
-    switch (rc) {
587943
+    switch (interactive_fence_level) {
587943
         case 3:
587943
             options.mon_ops |= mon_op_fence_full_history | mon_op_fence_history | mon_op_fence_connect;
587943
             return include_exclude_cb("--include", "fencing", data, err);
587943
@@ -862,6 +864,38 @@ cib_connect(gboolean full)
587943
     return rc;
587943
 }
587943
 
587943
+/* This is used to set up the fencing options after the interactive UI has been stared.
587943
+ * fence_history_cb can't be used because it builds up a list of includes/excludes that
587943
+ * then have to be processed with apply_include_exclude and that could affect other
587943
+ * things.
587943
+ */
587943
+static void
587943
+set_fencing_options(int level)
587943
+{
587943
+    switch (level) {
587943
+        case 3:
587943
+            options.mon_ops |= mon_op_fence_full_history | mon_op_fence_history | mon_op_fence_connect;
587943
+            show |= mon_show_fencing_all;
587943
+            break;
587943
+
587943
+        case 2:
587943
+            options.mon_ops |= mon_op_fence_history | mon_op_fence_connect;
587943
+            show |= mon_show_fencing_all;
587943
+            break;
587943
+
587943
+        case 1:
587943
+            options.mon_ops |= mon_op_fence_history | mon_op_fence_connect;
587943
+            show |= mon_show_fence_failed | mon_show_fence_pending;
587943
+            break;
587943
+
587943
+        default:
587943
+            level = 0;
587943
+            options.mon_ops &= ~(mon_op_fence_history | mon_op_fence_connect);
587943
+            show &= ~mon_show_fencing_all;
587943
+            break;
587943
+    }
587943
+}
587943
+
587943
 #if CURSES_ENABLED
587943
 static const char *
587943
 get_option_desc(char c)
587943
@@ -900,23 +934,12 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat
587943
 
587943
         switch (c) {
587943
             case 'm':
587943
-                if (!pcmk_is_set(show, mon_show_fencing_all)) {
587943
-                    options.mon_ops |= mon_op_fence_history;
587943
-                    options.mon_ops |= mon_op_fence_connect;
587943
-                    if (st == NULL) {
587943
-                        mon_cib_connection_destroy(NULL);
587943
-                    }
587943
-                }
587943
-
587943
-                if (pcmk_any_flags_set(show,
587943
-                                       mon_show_fence_failed
587943
-                                       |mon_show_fence_pending
587943
-                                       |mon_show_fence_worked)) {
587943
-                    show &= ~mon_show_fencing_all;
587943
-                } else {
587943
-                    show |= mon_show_fencing_all;
587943
+                interactive_fence_level++;
587943
+                if (interactive_fence_level > 3) {
587943
+                    interactive_fence_level = 0;
587943
                 }
587943
 
587943
+                set_fencing_options(interactive_fence_level);
587943
                 break;
587943
             case 'c':
587943
                 show ^= mon_show_tickets;
587943
@@ -997,10 +1020,7 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat
587943
         print_option_help(out, 'R', pcmk_is_set(options.mon_ops, mon_op_print_clone_detail));
587943
         print_option_help(out, 'b', pcmk_is_set(options.mon_ops, mon_op_print_brief));
587943
         print_option_help(out, 'j', pcmk_is_set(options.mon_ops, mon_op_print_pending));
587943
-        print_option_help(out, 'm', pcmk_any_flags_set(show,
587943
-                                                       mon_show_fence_failed
587943
-                                                      |mon_show_fence_pending
587943
-                                                      |mon_show_fence_worked));
587943
+        out->info(out, "%d m: \t%s", interactive_fence_level, get_option_desc('m'));
587943
         out->info(out, "%s", "\nToggle fields via field letter, type any other key to return");
587943
     }
587943
 
587943
@@ -1400,6 +1420,19 @@ main(int argc, char **argv)
587943
         return clean_up(CRM_EX_USAGE);
587943
     }
587943
 
587943
+    /* Sync up the initial value of interactive_fence_level with whatever was set with
587943
+     * --include/--exclude= options.
587943
+     */
587943
+    if (pcmk_is_set(show, mon_show_fencing_all)) {
587943
+        interactive_fence_level = 3;
587943
+    } else if (pcmk_is_set(show, mon_show_fence_worked)) {
587943
+        interactive_fence_level = 2;
587943
+    } else if (pcmk_any_flags_set(show, mon_show_fence_failed | mon_show_fence_pending)) {
587943
+        interactive_fence_level = 1;
587943
+    } else {
587943
+        interactive_fence_level = 0;
587943
+    }
587943
+
587943
     crm_mon_register_messages(out);
587943
     pe__register_messages(out);
587943
     stonith__register_messages(out);
587943
@@ -1460,6 +1493,7 @@ main(int argc, char **argv)
587943
     } while (rc == -ENOTCONN);
587943
 
587943
     handle_connection_failures(rc);
587943
+    set_fencing_options(interactive_fence_level);
587943
     mon_refresh_display(NULL);
587943
 
587943
     mainloop = g_main_loop_new(NULL, FALSE);
587943
-- 
587943
1.8.3.1
587943