Refactoring: Changed all check parameters starting with a 'p' to the new rulespec...
[check_mk.git] / livestatus / src / Logfile.h
blob5f070685a33a6dea72648596b447256e67e67415
1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
7 // | |
8 // | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
9 // +------------------------------------------------------------------+
11 // This file is part of Check_MK.
12 // The official homepage is at http://mathias-kettner.de/check_mk.
14 // check_mk is free software; you can redistribute it and/or modify it
15 // under the terms of the GNU General Public License as published by
16 // the Free Software Foundation in version 2. check_mk is distributed
17 // in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
18 // out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 // PARTICULAR PURPOSE. See the GNU General Public License for more de-
20 // tails. You should have received a copy of the GNU General Public
21 // License along with GNU Make; see the file COPYING. If not, write
22 // to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 // Boston, MA 02110-1301 USA.
25 #ifndef Logfile_h
26 #define Logfile_h
28 #include "config.h" // IWYU pragma: keep
29 #include <cstdint>
30 #include <cstdio>
31 #include <ctime>
32 #include <map>
33 #include <memory>
34 #include <string>
35 #include "FileSystem.h"
36 class LogCache;
37 class LogEntry;
38 class Logger;
39 class MonitoringCore;
40 class Query;
42 #ifdef CMC
43 class World;
44 #endif
46 // key is time_t . lineno
47 using logfile_entries_t = std::map<uint64_t, std::unique_ptr<LogEntry>>;
49 class Logfile {
50 public:
51 Logfile(MonitoringCore *mc, LogCache *logcache, fs::path path, bool watch);
52 fs::path path() const { return _path; }
54 // for tricky protocol between LogCache::logLineHasBeenAdded and this class
55 void flush();
56 time_t since() const { return _since; }
57 unsigned classesRead() const { return _logclasses_read; }
58 size_t size() const { return _entries.size(); }
59 long freeMessages(unsigned logclasses);
61 // for TableStateHistory
62 const logfile_entries_t *getEntriesFor(unsigned logclasses);
64 // for TableLog::answerQuery
65 bool answerQueryReverse(Query *query, time_t since, time_t until,
66 unsigned logclasses);
68 private:
69 MonitoringCore *const _mc;
70 LogCache *const _logcache;
71 const fs::path _path;
72 const time_t _since; // time of first entry
73 const bool _watch; // true only for current logfile
74 fpos_t _read_pos; // read until this position
75 size_t _lineno; // read until this line
76 logfile_entries_t _entries;
77 #ifdef CMC
78 World *_world; // CMC: world our references point into
79 #endif
80 unsigned _logclasses_read; // only these types have been read
82 void load(unsigned logclasses);
83 void loadRange(FILE *file, unsigned missing_types, unsigned logclasses);
84 bool processLogLine(size_t lineno, std::string line, unsigned logclasses);
85 uint64_t makeKey(time_t t, size_t lineno);
86 void updateReferences();
87 Logger *logger() const;
90 #endif // Logfile_h