forked from microsoft/OMS-Auditd-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperationalStatus.h
103 lines (77 loc) · 3.54 KB
/
OperationalStatus.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
microsoft-oms-auditd-plugin
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef AUOMS_OPERATIONALSTATUS_H
#define AUOMS_OPERATIONALSTATUS_H
#include "UnixDomainListener.h"
#include "RunBase.h"
#include "EventQueue.h"
#include "PriorityQueue.h"
#include "CmdlineRedactor.h"
#include "AuditRules.h"
#include <string>
#include <vector>
#include <functional>
/*
* Statuses
* No collection
* auditd installed but not running
* auditd not installed, other process collecting
* -e 2 is set and desired rules not loaded
* auditd present
* auditd absent
* Could not update auditd rules
* Could not update kernel rules
*/
enum class ErrorCategory {
DATA_COLLECTION,
DESIRED_RULES,
AUDIT_RULES_KERNEL,
AUDIT_RULES_FILE,
MISSING_REDACTION_RULES,
};
class OperationalStatusListener: public RunBase {
public:
explicit OperationalStatusListener(const std::string socket_path, std::function<std::string()>&& status_fn): _listener(socket_path), _status_fn(status_fn) {}
bool Initialize();
protected:
void on_stopping() override;
void run() override;
private:
void handle_connection(int fd);
UnixDomainListener _listener;
std::function<std::string()> _status_fn;
};
class OperationalStatus: public RunBase {
public:
explicit OperationalStatus(const std::string socket_path, std::shared_ptr<PriorityQueue> queue):
_listener(socket_path, [this]() -> std::string { return get_status_str();}),
_error_conditions(), _builder(std::make_shared<EventQueue>(std::move(queue)), nullptr) {}
bool Initialize();
std::vector<std::pair<ErrorCategory, std::string>> GetErrors();
void SetErrorCondition(ErrorCategory category, const std::string& error_msg);
void ClearErrorCondition(ErrorCategory category);
void SetDesiredAuditRules(const std::vector<AuditRule>& rules);
void SetLoadedAuditRules(const std::vector<AuditRule>& rules);
void SetRedactionRules(const std::vector<std::shared_ptr<const CmdlineRedactionRule>>& rules);
protected:
void on_stopping() override;
void run() override;
private:
std::string get_status_str();
std::string get_json_status();
bool send_status();
OperationalStatusListener _listener;
std::unordered_map<ErrorCategory, std::string> _error_conditions;
EventBuilder _builder;
std::string _desired_audit_rules;
std::string _loaded_audit_rules;
std::string _redaction_rules;
};
#endif //AUOMS_OPERATIONALSTATUS_H