-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsermon_app.hpp
More file actions
86 lines (74 loc) · 2.97 KB
/
Copy pathsermon_app.hpp
File metadata and controls
86 lines (74 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* @(#)sermon_app.hpp
*/
#pragma once
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <mutex>
#include "notify.hpp"
#include "service_fail.hpp"
#include "json/src/json.hpp"
class Sermon
{
public:
struct Service
{
std::string url;
std::string name;
double timeout; /* in seconds */
bool checkCertificates;
};
Sermon(std::string configFile="");
virtual ~Sermon();
/* Let's play! */
void monitoring();
void exit();
void say(std::string what, int verbosity=5);
std::vector<nlohmann::json> currentOutages(bool allData = false);
/* Options, we can include min. outage times, unrecovered, etc */
nlohmann::json getHistoryOutages(time_t from, time_t to, const std::vector<std::string>& services = {}, const std::map<std::string, std::string>& options = {});
nlohmann::json getHistoryOutage(std::string uuid);
nlohmann::json getHistoryOutage(uint64_t outageId);
nlohmann::json getServiceStats(time_t from, time_t to, const std::vector<std::string>& services = {}, const std::map<std::string, std::string>& options = {});
nlohmann::json getServiceStats(time_t from, time_t to, const uint64_t serviceId, const std::map<std::string, std::string>& options = {});
nlohmann::json getServicesBasicData(const std::vector<std::string>& services = {}, const std::map<std::string, std::string>& options = {});
void changeOutageDescription(uint64_t outageId, std::string description);
void changeOutageTags(uint64_t outageId, std::string tags);
void setOutageStatusError(uint64_t outageId, int error);
bool paused();
bool paused(bool status);
std::string lastAction();
std::string lastProbe();
std::chrono::system_clock::time_point lastActionDtm();
std::chrono::system_clock::time_point lastProbeDtm();
protected:
void debug_notifiers();
void debug_services();
void serviceFail(const Service& s, int code, const std::string& message);
void removePendingFails(const Service &s);
void insertNotifier(const nlohmann::json ¬ifierJson);
void insertService(const nlohmann::json &serviceJson);
void siteProbe(Sermon::Service serv);
int getUrlData(std::string url, std::string &out, double timeout=-1, bool checkCertificates=true, int max_redirects=2);
std::string lastAction(std::string action);
std::string lastProbe(std::string action);
private:
void loadConfig(std::string configFile);
long tbp; /* Time between probes*/
long sap; /* Sleep after probe (ms)*/
int verbosity; /* Verbosity level*/
int maxRedirects; /* Maximum redirects*/
double timeout; /* Default timeout for all services */
bool checkCertificates; /* Check certificates?*/
bool __exit;
bool __paused; /* Paused? */
std::string __lastAction;
std::string __lastProbe;
std::chrono::system_clock::time_point __lastActionDtm;
std::chrono::system_clock::time_point __lastProbeDtm;
std::vector <std::shared_ptr<Notify>> notifiers;
std::vector <Service> services;
std::mutex currentFails_mutex;
std::map <std::string, ServiceFail> currentFails;
};