method to write host status records to the persistent store.
| 514 | |
| 515 | // method to write host status records to the persistent store. |
| 516 | void |
| 517 | HostStatusSync::sync_task() |
| 518 | { |
| 519 | YAML::Node records{YAML::NodeType::Map}; |
| 520 | |
| 521 | YAML::Node statusList{YAML::NodeType::Sequence}; |
| 522 | std::vector<HostStatuses> statuses; |
| 523 | HostStatus &hs = HostStatus::instance(); |
| 524 | hs.getAllHostStatuses(statuses); |
| 525 | |
| 526 | for (auto &&h : statuses) { |
| 527 | YAML::Node host{YAML::NodeType::Map}; |
| 528 | host[HOST_NAME_KEY] = h.hostname; |
| 529 | host[STATUS_KEY] = h.status; |
| 530 | statusList.push_back(host); |
| 531 | } |
| 532 | records["statuses"] = statusList; |
| 533 | |
| 534 | std::ofstream fout; |
| 535 | fout.open(hostRecordsFile.c_str(), std::ofstream::out | std::ofstream::trunc); |
| 536 | if (fout) { |
| 537 | fout << records; |
| 538 | fout << '\n'; |
| 539 | fout.close(); |
| 540 | } else { |
| 541 | Warning("failed to open %s for writing", hostRecordsFile.c_str()); |
| 542 | } |
| 543 | } |
nothing calls this directly
no test coverage detected