-
Notifications
You must be signed in to change notification settings - Fork 339
/
splitlivelogs.py
executable file
·74 lines (62 loc) · 2.42 KB
/
splitlivelogs.py
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
#!/usr/bin/env python
# Copyright (C) 2009-2014:
# Gabes Jean, naparuba@gmail.com
# Gerhard Lausser, Gerhard.Lausser@consol.de
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
"""
This script will take the sqlite database of the livestatus module and
split up the contents in single datafiles (1 for each day of data found).
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
import optparse
import os
sys.path.append("..")
sys.path.append("../shinken")
sys.path.append("../../shinken")
sys.path.append("../../../shinken")
#sys.path.append("../bin")
#sys.path.append(os.path.abspath("bin"))
#import shinken
from shinken.modules.livestatus_broker.livestatus_db import LiveStatusDb
parser = optparse.OptionParser(
"%prog [options] -d database [-a archive]")
parser.add_option('-d', '--database', action='store',
dest="database",
help="The sqlite datafile of your livestatus module")
parser.add_option('-a', '--archive', action='store',
dest="archive_path",
help="(optional) path to the archive directory")
opts, args = parser.parse_args()
if not opts.database:
parser.error("Requires at least the database file (option -d/--database")
if not opts.archive_path:
opts.archive_path = os.path.join(os.path.dirname(opts.database), 'archives')
pass
# Protect for windows multiprocessing that will RELAUNCH all
if __name__ == '__main__':
if os.path.exists(opts.database):
try:
os.stat(opts.archive_path)
except Exception:
os.mkdir(opts.archive_path)
dbh = LiveStatusDb(opts.database, opts.archive_path, 3600)
dbh.log_db_do_archive()
dbh.close()
else:
print("database %s does not exist" % opts.database)
# For perf tuning: