bool LogMonitor::preprocess_command(MonOpRequestRef op)
{
op->mark_logmon_event("preprocess_command");
- int r = -1;
+ MMonCommand *m = static_cast<MMonCommand*>(op->get_req());
+ int r = -EINVAL;
bufferlist rdata;
stringstream ss;
- if (r != -1) {
- string rs;
- getline(ss, rs);
- mon->reply_command(op, r, rs, rdata, get_last_committed());
+ map<string, cmd_vartype> cmdmap;
+ if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) {
+ string rs = ss.str();
+ mon->reply_command(op, -EINVAL, rs, get_last_committed());
return true;
- } else
+ }
+ MonSession *session = m->get_session();
+ if (!session) {
+ mon->reply_command(op, -EACCES, "access denied", get_last_committed());
+ return true;
+ }
+
+ string prefix;
+ cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
+
+ string format;
+ cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
+ boost::scoped_ptr<Formatter> f(Formatter::create(format));
+
+ if (prefix == "log last") {
+ int64_t num = 20;
+ cmd_getval(g_ceph_context, cmdmap, "num", num);
+ if (f) {
+ f->open_array_section("tail");
+ }
+ auto p = summary.tail.end();
+ while (num > 0 && p != summary.tail.begin()) {
+ num--;
+ --p;
+ }
+ ostringstream ss;
+ for ( ; p != summary.tail.end(); ++p) {
+ if (f) {
+ f->dump_object("entry", *p);
+ } else {
+ ss << *p << "\n";
+ }
+ }
+ if (f) {
+ f->close_section();
+ f->flush(rdata);
+ } else {
+ rdata.append(ss.str());
+ }
+ r = 0;
+ } else {
return false;
+ }
+
+ string rs;
+ getline(ss, rs);
+ mon->reply_command(op, r, rs, rdata, get_last_committed());
+ return true;
}
COMMAND("fsid", "show cluster FSID/UUID", "mon", "r", "cli,rest")
COMMAND("log name=logtext,type=CephString,n=N", \
"log supplied text to the monitor log", "mon", "rw", "cli,rest")
+COMMAND("log last name=num,type=CephInt,range=1,req=false", \
+ "print last few lines of the cluster log", \
+ "mon", "rw", "cli,rest")
COMMAND_WITH_FLAG("injectargs " \
"name=injected_args,type=CephString,n=N", \
"inject config arguments into monitor", "mon", "rw", "cli,rest",