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