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