diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-12-08 01:50:55 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-12-08 01:50:55 +1030 |
commit | a46c3b4f2ada1b59fc52a8d8684720af690e0cc8 (patch) | |
tree | c5600ac344a0e7129c23b731270320fc7c1e1cfb /ctdb/tools/ctdb.c | |
parent | 5d99a1a47c1d3d99fe917ee87f0fcc1a73442ccb (diff) | |
download | samba-a46c3b4f2ada1b59fc52a8d8684720af690e0cc8.tar.gz samba-a46c3b4f2ada1b59fc52a8d8684720af690e0cc8.tar.xz samba-a46c3b4f2ada1b59fc52a8d8684720af690e0cc8.zip |
ctdb: scriptstatus can now query non-monitor events
We also no longer return an error before scripts have been run; a special
zero-length data means we have never run the scripts.
"ctdb scriptstatus all" returns all event script results.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(This used to be ctdb commit 9b90d671581e390e2892d3a68f3ca98d58bef4df)
Diffstat (limited to 'ctdb/tools/ctdb.c')
-rw-r--r-- | ctdb/tools/ctdb.c | 80 |
1 files changed, 68 insertions, 12 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index c9b0d78dcd..c210a20475 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -725,25 +725,33 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a return 0; } - /* - display the status of the monitoring scripts + display the status of the scripts for monitoring (or other events) */ -static int control_scriptstatus(struct ctdb_context *ctdb, int argc, const char **argv) +static int control_one_scriptstatus(struct ctdb_context *ctdb, + enum ctdb_eventscript_call type) { - int i, ret; struct ctdb_scripts_wire *script_status; + int ret, i; - ret = ctdb_ctrl_getscriptstatus(ctdb, TIMELIMIT(), options.pnn, ctdb, &script_status); + ret = ctdb_ctrl_getscriptstatus(ctdb, TIMELIMIT(), options.pnn, ctdb, type, &script_status); if (ret != 0) { DEBUG(DEBUG_ERR, ("Unable to get script status from node %u\n", options.pnn)); return ret; } - if (options.machinereadable) { - printf(":Name:Code:Status:Start:End:Error Output...:\n"); - } else { - printf("%d scripts were executed last monitoring cycle\n", script_status->num_scripts); + if (script_status == NULL) { + if (!options.machinereadable) { + printf("%s cycle never run\n", + ctdb_eventscript_call_names[type]); + } + return 0; + } + + if (!options.machinereadable) { + printf("%d scripts were executed last %s cycle\n", + script_status->num_scripts, + ctdb_eventscript_call_names[type]); } for (i=0; i<script_status->num_scripts; i++) { const char *status = NULL; @@ -764,7 +772,8 @@ static int control_scriptstatus(struct ctdb_context *ctdb, int argc, const char break; } if (options.machinereadable) { - printf("%s:%i:%s:%lu.%06lu:%lu.%06lu:%s:\n", + printf("%s:%s:%i:%s:%lu.%06lu:%lu.%06lu:%s:\n", + ctdb_eventscript_call_names[type], script_status->scripts[i].name, script_status->scripts[i].status, status, @@ -798,10 +807,57 @@ static int control_scriptstatus(struct ctdb_context *ctdb, int argc, const char script_status->scripts[i].output); } } + return 0; +} + + +static int control_scriptstatus(struct ctdb_context *ctdb, + int argc, const char **argv) +{ + int ret; + enum ctdb_eventscript_call type, min, max; + const char *arg; + + if (argc > 1) { + DEBUG(DEBUG_ERR, ("Unknown arguments to scriptstatus\n")); + return -1; + } + + if (argc == 0) + arg = ctdb_eventscript_call_names[CTDB_EVENT_MONITOR]; + else + arg = argv[0]; + + for (type = 0; type < CTDB_EVENT_MAX; type++) { + if (strcmp(arg, ctdb_eventscript_call_names[type]) == 0) { + min = type; + max = type+1; + break; + } + } + if (type == CTDB_EVENT_MAX) { + if (strcmp(arg, "all") == 0) { + min = 0; + max = CTDB_EVENT_MAX; + } else { + DEBUG(DEBUG_ERR, ("Unknown event type %s\n", argv[0])); + return -1; + } + } + + if (options.machinereadable) { + printf(":Type:Name:Code:Status:Start:End:Error Output...:\n"); + } + + for (type = min; type < max; type++) { + ret = control_one_scriptstatus(ctdb, type); + if (ret != 0) { + return ret; + } + } return 0; } - /* enable an eventscript @@ -3792,7 +3848,7 @@ static const struct { { "wipedb", control_wipedb, false, false, "wipe the contents of a database.", "<dbname>"}, { "recmaster", control_recmaster, false, false, "show the pnn for the recovery master."}, { "setflags", control_setflags, false, false, "set flags for a node in the nodemap.", "<node> <flags>"}, - { "scriptstatus", control_scriptstatus, false, false, "show the status of the monitoring scripts"}, + { "scriptstatus", control_scriptstatus, false, false, "show the status of the monitoring scripts (or all scripts)", "[all]"}, { "enablescript", control_enablescript, false, false, "enable an eventscript", "<script>"}, { "disablescript", control_disablescript, false, false, "disable an eventscript", "<script>"}, { "natgwlist", control_natgwlist, false, false, "show the nodes belonging to this natgw configuration"}, |