repmgr: add --csv output to "cluster event"

Implements GitHub #471.
This commit is contained in:
Ian Barwick
2018-07-13 11:19:12 +09:00
parent 388ac2f392
commit b3f64987cb
4 changed files with 101 additions and 53 deletions

View File

@@ -7,6 +7,7 @@
GitHub #456 (Ian) GitHub #456 (Ian)
repmgr: "node check" and "node status" returns non-zero value if an issue repmgr: "node check" and "node status" returns non-zero value if an issue
encountered (Ian) encountered (Ian)
repmgr: add CSV output mode to "cluster event"; GitHub #471 (Ian)
repmgr: "node status" returns non-zero value if an issue encountered (Ian) repmgr: "node status" returns non-zero value if an issue encountered (Ian)
repmgrd: create a PID file by default; GitHub #457 (Ian) repmgrd: create a PID file by default; GitHub #457 (Ian)
repmgrd: daemonize process by default; GitHub #458 (Ian) repmgrd: daemonize process by default; GitHub #458 (Ian)

View File

@@ -68,14 +68,21 @@
<listitem> <listitem>
<para> <para>
<command><link linkend="repmgr-cluster-show">repmgr cluster-show</link></command>, <command><link linkend="repmgr-cluster-show">repmgr cluster show</link></command>,
<command><link linkend="repmgr-node-check">repmgr node check</link></command> and <command><link linkend="repmgr-node-check">repmgr node check</link></command> and
<command><link linkend="repmgr-node-status">repmgr node status</link></command> <command><link linkend="repmgr-node-status">repmgr node status</link></command>
return non-zero exit code if node status issues detected. (GitHub #456). return non-zero exit code if node status issues detected. (GitHub #456).
</para> </para>
</listitem> </listitem>
<listitem>
<para>
Add <option>--csv</option> output option for
<command><link linkend="repmgr-cluster-event">repmgr cluster event</link></command>.
(GitHub #471).
</para>
</listitem>
</itemizedlist> </itemizedlist>
</para> </para>
</sect2> </sect2>

View File

@@ -49,6 +49,22 @@
</para> </para>
</refsect1> </refsect1>
<refsect1>
<title>Output format</title>
<para>
<itemizedlist spacing="compact" mark="bullet">
<listitem>
<simpara>
<literal>--csv</literal>: generate output in CSV format. Note that the <literal>Details</literal>
column will currently not be emitted in CSV format.
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
<refsect1> <refsect1>
<title>Example</title> <title>Example</title>
<para> <para>

View File

@@ -463,6 +463,7 @@ do_cluster_show(void)
* --all * --all
* --node-[id|name] * --node-[id|name]
* --event * --event
* --csv
*/ */
void void
@@ -507,8 +508,12 @@ do_cluster_event(void)
strncpy(headers_event[EV_TIMESTAMP].title, _("Timestamp"), MAXLEN); strncpy(headers_event[EV_TIMESTAMP].title, _("Timestamp"), MAXLEN);
strncpy(headers_event[EV_DETAILS].title, _("Details"), MAXLEN); strncpy(headers_event[EV_DETAILS].title, _("Details"), MAXLEN);
/* if --terse provided, simply omit the "Details" column */ /*
if (runtime_options.terse == true) * If --terse or --csv provided, simply omit the "Details" column.
* In --csv mode we'd need to quote/escape the contents "Details" column,
* which is doable but which will remain a TODO for now.
*/
if (runtime_options.terse == true || runtime_options.output_mode == OM_CSV)
column_count --; column_count --;
for (i = 0; i < column_count; i++) for (i = 0; i < column_count; i++)
@@ -531,6 +536,8 @@ do_cluster_event(void)
} }
if (runtime_options.output_mode == OM_TEXT)
{
for (i = 0; i < column_count; i++) for (i = 0; i < column_count; i++)
{ {
if (i == 0) if (i == 0)
@@ -558,11 +565,25 @@ do_cluster_event(void)
} }
printf("\n"); printf("\n");
}
for (i = 0; i < PQntuples(res); i++) for (i = 0; i < PQntuples(res); i++)
{ {
int j; int j;
if (runtime_options.output_mode == OM_CSV)
{
for (j = 0; j < column_count; j++)
{
printf("%s", PQgetvalue(res, i, j));
if ((j + 1) < column_count)
{
printf(",");
}
}
}
else
{
printf(" "); printf(" ");
for (j = 0; j < column_count; j++) for (j = 0; j < column_count; j++)
{ {
@@ -573,6 +594,7 @@ do_cluster_event(void)
if (j < (column_count - 1)) if (j < (column_count - 1))
printf(" | "); printf(" | ");
} }
}
printf("\n"); printf("\n");
} }
@@ -581,6 +603,7 @@ do_cluster_event(void)
PQfinish(conn); PQfinish(conn);
if (runtime_options.output_mode == OM_TEXT)
puts(""); puts("");
} }
@@ -1414,6 +1437,7 @@ do_cluster_help(void)
printf(_(" --event filter specific event\n")); printf(_(" --event filter specific event\n"));
printf(_(" --node-id restrict entries to node with this ID\n")); printf(_(" --node-id restrict entries to node with this ID\n"));
printf(_(" --node-name restrict entries to node with this name\n")); printf(_(" --node-name restrict entries to node with this name\n"));
printf(_(" --csv emit output as CSV\n"));
puts(""); puts("");
printf(_("CLUSTER CLEANUP\n")); printf(_("CLUSTER CLEANUP\n"));