1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 #include "config.h" // IWYU pragma: keep
35 #include "FileSystem.h"
46 // key is time_t . lineno
47 using logfile_entries_t
= std::map
<uint64_t, std::unique_ptr
<LogEntry
>>;
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
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
,
69 MonitoringCore
*const _mc
;
70 LogCache
*const _logcache
;
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
;
78 World
*_world
; // CMC: world our references point into
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;