MCPcopy Create free account
hub / github.com/apache/trafficserver / server_get_status

Function server_get_status

src/proxy/HostStatus.cc:430–478  ·  view source on GitHub ↗

JSON-RPC method to retrieve host status information.

Source from the content-addressed store, hash-verified

428
429// JSON-RPC method to retrieve host status information.
430swoc::Rv<YAML::Node>
431server_get_status(std::string_view /* id ATS_UNUSED */, YAML::Node const &params)
432{
433 namespace err = rpc::handlers::errors;
434 swoc::Rv<YAML::Node> resp;
435 YAML::Node statusList{YAML::NodeType::Sequence}, errorList{YAML::NodeType::Sequence};
436
437 try {
438 if (!params.IsNull() && params.size() > 0) { // returns host statuses for just the ones asked for.
439 for (YAML::const_iterator it = params.begin(); it != params.end(); ++it) {
440 YAML::Node host{YAML::NodeType::Map};
441 auto name = it->as<std::string>();
442 HostStatRec *host_rec = nullptr;
443 HostStatus &hs = HostStatus::instance();
444 host_rec = hs.getHostStatus(name);
445 if (host_rec == nullptr) {
446 Dbg(dbg_ctl_host_statuses, "no record for %s was found", name.c_str());
447 errorList.push_back("no record for " + name + " was found");
448 continue;
449 } else {
450 std::stringstream s;
451 s << *host_rec;
452 host[HOST_NAME_KEY] = name;
453 host[STATUS_KEY] = s.str();
454 statusList.push_back(host);
455 Dbg(dbg_ctl_host_statuses, "hostname: %s, status: %s", name.c_str(), s.str().c_str());
456 }
457 }
458 } else { // return all host statuses.
459 std::vector<HostStatuses> hostInfo;
460 HostStatus &hs = HostStatus::instance();
461 hs.getAllHostStatuses(hostInfo);
462 for (auto &h : hostInfo) {
463 YAML::Node host{YAML::NodeType::Map};
464 host[HOST_NAME_KEY] = h.hostname;
465 host[STATUS_KEY] = h.status;
466 statusList.push_back(host);
467 }
468 }
469 } catch (std::exception const &ex) {
470 Dbg(dbg_ctl_host_statuses, "Got an error decoding the parameters: %s", ex.what());
471 errorList.push_back("Error decoding parameters : " + std::string(ex.what()));
472 }
473
474 resp.result()[STATUS_LIST_KEY] = statusList;
475 resp.result()[ERROR_LIST_KEY] = errorList;
476
477 return resp;
478}
479
480// JSON-RPC method to mark up or down a host.
481swoc::Rv<YAML::Node>

Callers

nothing calls this directly

Calls 11

stringClass · 0.85
getAllHostStatusesMethod · 0.80
resultMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getHostStatusMethod · 0.45
c_strMethod · 0.45
push_backMethod · 0.45
strMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected