1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

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)
This commit is contained in:
Rusty Russell 2009-12-08 01:50:55 +10:30
parent 5d99a1a47c
commit a46c3b4f2a
6 changed files with 101 additions and 31 deletions

View File

@ -3643,27 +3643,35 @@ int switch_from_server_to_client(struct ctdb_context *ctdb)
}
/*
get the status of running the monitor eventscripts
get the status of running the monitor eventscripts: NULL means never run.
*/
int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb,
struct timeval timeout, uint32_t destnode,
TALLOC_CTX *mem_ctx,
TALLOC_CTX *mem_ctx, enum ctdb_eventscript_call type,
struct ctdb_scripts_wire **script_status)
{
int ret;
TDB_DATA outdata;
TDB_DATA outdata, indata;
int32_t res;
uint32_t uinttype = type;
indata.dptr = (uint8_t *)&uinttype;
indata.dsize = sizeof(uinttype);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS, 0, tdb_null,
CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS, 0, indata,
mem_ctx, &outdata, &res, &timeout, NULL);
if (ret != 0 || res != 0 || outdata.dsize == 0) {
if (ret != 0 || res != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getscriptstatus failed ret:%d res:%d\n", ret, res));
return -1;
}
*script_status = (struct ctdb_scripts_wire *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
talloc_free(outdata.dptr);
if (outdata.dsize == 0) {
*script_status = NULL;
} else {
*script_status = (struct ctdb_scripts_wire *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
talloc_free(outdata.dptr);
}
return 0;
}

View File

@ -687,7 +687,8 @@ extern const char *ctdb_eventscript_call_names[];
int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb,
struct timeval timeout, uint32_t destnode,
TALLOC_CTX *mem_ctx, struct ctdb_scripts_wire **script_status);
TALLOC_CTX *mem_ctx, enum ctdb_eventscript_call type,
struct ctdb_scripts_wire **script_status);
struct debug_levels {

View File

@ -1489,7 +1489,9 @@ int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb, uint32_t opcode, T
extern int script_log_level;
int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata);
int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
uint32_t call_type,
TDB_DATA *outdata);
int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval timeout, double latency);

View File

@ -433,8 +433,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
return ctdb_control_recd_ping(ctdb);
case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS:
CHECK_CONTROL_DATA_SIZE(0);
return ctdb_control_get_event_script_status(ctdb, outdata);
CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
return ctdb_control_get_event_script_status(ctdb, *(uint32_t *)indata.dptr, outdata);
case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
CHECK_CONTROL_DATA_SIZE(sizeof(double));

View File

@ -98,18 +98,21 @@ static void log_event_script_output(const char *str, uint16_t len, void *p)
memcpy(current->output + slen, str, min);
}
int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata)
int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
uint32_t call_type,
TDB_DATA *outdata)
{
struct ctdb_scripts_wire *monitoring_scripts = ctdb->last_status[CTDB_EVENT_MONITOR];
if (monitoring_scripts == NULL) {
DEBUG(DEBUG_ERR,(__location__ " last_monitor_status_ctx is NULL when reading status\n"));
if (call_type >= CTDB_EVENT_MAX) {
return -1;
}
outdata->dsize = talloc_get_size(monitoring_scripts);
outdata->dptr = (uint8_t *)monitoring_scripts;
if (ctdb->last_status[call_type] == NULL) {
/* If it's never been run, return nothing so they can tell. */
outdata->dsize = 0;
} else {
outdata->dsize = talloc_get_size(ctdb->last_status[call_type]);
outdata->dptr = (uint8_t *)ctdb->last_status[call_type];
}
return 0;
}

View File

@ -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"},