summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-02-02 17:32:42 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-02-02 17:32:42 +0000
commit61d3cf19745a6b52d3ce84f797ce51124c68629e (patch)
tree9a50da351a30b72bd7eb7e60bf36ff5d86523770
parentSimplify packPqVar with if constexpr (diff)
downloadgentoobrowse-api-61d3cf19745a6b52d3ce84f797ce51124c68629e.tar.bz2
gentoobrowse-api-61d3cf19745a6b52d3ce84f797ce51124c68629e.tar.xz
gentoobrowse-api-61d3cf19745a6b52d3ce84f797ce51124c68629e.zip
Submit Nagios passive check results for maintanence jobsgentoobrowse-api-0.11.1
-rw-r--r--gentoobrowse-api/service/maintenanceBugs.cpp60
-rw-r--r--gentoobrowse-api/service/maintenanceGitOperations.cpp27
2 files changed, 53 insertions, 34 deletions
diff --git a/gentoobrowse-api/service/maintenanceBugs.cpp b/gentoobrowse-api/service/maintenanceBugs.cpp
index 9393cdf..aee9003 100644
--- a/gentoobrowse-api/service/maintenanceBugs.cpp
+++ b/gentoobrowse-api/service/maintenanceBugs.cpp
@@ -10,6 +10,7 @@
#include <utils/dbUtils.h>
#include <compileTimeFormatter.h>
#include <logger.h>
+#include <nagios.h>
namespace Gentoo {
namespace Service {
@@ -67,37 +68,46 @@ namespace Gentoo {
AdHocFormatter(UpdatingBugs, "Refreshing bug list from %?");
AdHocFormatter(UpdatingBugUrl, " ... %?");
AdHocFormatter(UpdatingBugsResult, "Refreshed bug list: %? added, %? updated, %? removed");
+ constexpr const std::string_view NagiosServiceName("GB API Bug Updates");
void
Maintenance::refreshBugs(const Ice::Current & c)
{
- auto log = LOGMANAGER()->getLogger(__FUNCTION__);
- std::filesystem::path root = properties(c)->getPropertyWithDefault(
- "GentooBrowseAPI.BugRoot", "https://bugs.gentoo.org/data/cached");
+ try {
+ auto log = LOGMANAGER()->getLogger(__FUNCTION__);
+ std::filesystem::path root = properties(c)->getPropertyWithDefault(
+ "GentooBrowseAPI.BugRoot", "https://bugs.gentoo.org/data/cached");
- log->messagectf<UpdatingBugs>(IceTray::Logging::LogLevel::INFO, root);
- auto dbc = db->get();
- DB::TransactionScope tx(*dbc.get());
- DB::TablePatch tp;
- tp.pk = { "bugId" };
- tp.cols = { "bugId", "severity", "status", "summary" };
- tp.dest = "gentoobrowse.bugs";
- tp.src = Utils::Database::emptyClone(dbc.get(), "gentoobrowse.bugs");
- auto ins = Utils::Database::tablePatchInserter(dbc.get(), tp);
- BugListParser blp(ins);
- for(const auto & bl : {
+ log->messagectf<UpdatingBugs>(IceTray::Logging::LogLevel::INFO, root);
+ auto dbc = db->get();
+ DB::TransactionScope tx(*dbc.get());
+ DB::TablePatch tp;
+ tp.pk = { "bugId" };
+ tp.cols = { "bugId", "severity", "status", "summary" };
+ tp.dest = "gentoobrowse.bugs";
+ tp.src = Utils::Database::emptyClone(dbc.get(), "gentoobrowse.bugs");
+ auto ins = Utils::Database::tablePatchInserter(dbc.get(), tp);
+ BugListParser blp(ins);
+ for(const auto & bl : {
"buglist-CONFIRMED.html",
- "buglist-UNCONFIRMED.html",
- "buglist-IN_PROGRESS.html" }) {
- log->messagectf<UpdatingBugUrl>(IceTray::Logging::LogLevel::DEBUG, bl);
- AdHoc::Net::CurlStreamSource css(root / bl);
- css.setopt(CURLOPT_ENCODING, "deflate, gzip");
- css.setopt(CURLOPT_TIMEOUT, 20L);
- AdHoc::Net::CurlStream cs(css);
- blp.parse_stream(cs);
+ "buglist-UNCONFIRMED.html",
+ "buglist-IN_PROGRESS.html" }) {
+ log->messagectf<UpdatingBugUrl>(IceTray::Logging::LogLevel::DEBUG, bl);
+ AdHoc::Net::CurlStreamSource css(root / bl);
+ css.setopt(CURLOPT_ENCODING, "deflate, gzip");
+ css.setopt(CURLOPT_TIMEOUT, 20L);
+ AdHoc::Net::CurlStream cs(css);
+ blp.parse_stream(cs);
+ }
+ auto result = dbc->patchTable(&tp);
+ Utils::Database::drop(dbc.get(), tp.src);
+ log->messagectf<UpdatingBugsResult>(IceTray::Logging::LogLevel::INFO, result.inserts, result.updates, result.deletes);
+ AdHoc::submitNagiosPassiveServiceCheck(NagiosServiceName, AdHoc::NagiosStatusCode::OK,
+ UpdatingBugsResult::get(result.inserts, result.updates, result.deletes));
+ }
+ catch (const std::exception & ex) {
+ AdHoc::submitNagiosPassiveServiceCheck(NagiosServiceName, AdHoc::NagiosStatusCode::Warning, ex.what());
+ throw;
}
- auto result = dbc->patchTable(&tp);
- log->messagectf<UpdatingBugsResult>(IceTray::Logging::LogLevel::INFO, result.inserts, result.updates, result.deletes);
- Utils::Database::drop(dbc.get(), tp.src);
}
}
}
diff --git a/gentoobrowse-api/service/maintenanceGitOperations.cpp b/gentoobrowse-api/service/maintenanceGitOperations.cpp
index dae0da2..2a72fe6 100644
--- a/gentoobrowse-api/service/maintenanceGitOperations.cpp
+++ b/gentoobrowse-api/service/maintenanceGitOperations.cpp
@@ -15,6 +15,7 @@
#include <compileTimeFormatter.h>
#include <systemd/sd-daemon.h>
#include <logger.h>
+#include <nagios.h>
namespace Gentoo {
namespace Service {
@@ -166,19 +167,27 @@ namespace Gentoo {
return changes;
}
+ constexpr const std::string_view NagiosServiceName("GB API Package Updates");
void
Maintenance::refreshPackageTree(const Ice::Current & c)
{
- auto properties = c.adapter->getCommunicator()->getProperties();
- auto repoRoot = std::filesystem::path(properties->getPropertyWithDefault("GentooBrowseAPI.RepoRoot", "/"));
- auto dbc = db->get();
- DB::TransactionScope tx(*dbc.get());
- for (const auto & repo : fetch<Gentoo::Repositories>(dbc.get(), sql::maintenance::reposToGitRefresh)) {
- auto changes = refreshRepository(dbc.get(), properties, repo);
- this->applyFileChanges(dbc.get(), repoRoot, repo, changes);
+ try {
+ auto properties = c.adapter->getCommunicator()->getProperties();
+ auto repoRoot = std::filesystem::path(properties->getPropertyWithDefault("GentooBrowseAPI.RepoRoot", "/"));
+ auto dbc = db->get();
+ DB::TransactionScope tx(*dbc.get());
+ for (const auto & repo : fetch<Gentoo::Repositories>(dbc.get(), sql::maintenance::reposToGitRefresh)) {
+ auto changes = refreshRepository(dbc.get(), properties, repo);
+ this->applyFileChanges(dbc.get(), repoRoot, repo, changes);
+ }
+ time_t now = time(nullptr);
+ sd_notifyf(0, "STATUS=Last update %s", ctime(&now));
+ AdHoc::submitNagiosPassiveServiceCheck(NagiosServiceName, AdHoc::NagiosStatusCode::OK, "Package tree(s) updated");
+ }
+ catch (const std::exception & ex) {
+ AdHoc::submitNagiosPassiveServiceCheck(NagiosServiceName, AdHoc::NagiosStatusCode::Warning, ex.what());
+ throw;
}
- time_t now = time(nullptr);
- sd_notifyf(0, "STATUS=Last update %s", ctime(&now));
}
AdHocFormatter(UpdatingFileContent, "Updating file content");