-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python module for the icinga2.debug file
refs #6702
- Loading branch information
1 parent
e359c55
commit 1effe83
Showing
17 changed files
with
814 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Icinga 2 | ||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
find_package(PythonInterp REQUIRED) | ||
|
||
add_subdirectory(icinga2) | ||
|
||
configure_file(setup.py.cmake ${CMAKE_CURRENT_BINARY_DIR}/setup.py @ONLY) | ||
|
||
install(CODE "execute_process( | ||
COMMAND ${CMAKE_COMMAND} | ||
-DSETUP_PY=${CMAKE_CURRENT_BINARY_DIR}/setup.py | ||
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} | ||
-DPREFIX=${CMAKE_INSTALL_PREFIX} | ||
-DWDIR=${CMAKE_CURRENT_BINARY_DIR} | ||
-P ${PROJECT_SOURCE_DIR}/third-party/cmake/PythonSetup.cmake)" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Icinga 2 | ||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
add_subdirectory(commands) | ||
add_subdirectory(utils) | ||
|
||
configure_file(config.py.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.py @ONLY) | ||
configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py COPYONLY) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Icinga 2 | ||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py COPYONLY) | ||
configure_file(list_objects.py ${CMAKE_CURRENT_BINARY_DIR}/list_objects.py COPYONLY) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Icinga 2 | ||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from icinga2.utils.debug import ObjectsFile | ||
|
||
def main(): | ||
fp = open("/tmp/i2/var/cache/icinga2/icinga2.debug") | ||
of = ObjectsFile(fp) | ||
for obj in of: | ||
print obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Icinga 2 | ||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
Prefix = '@CMAKE_INSTALL_PREFIX@' | ||
SysconfDir = '@CMAKE_INSTALL_FULL_SYSCONFDIR@' | ||
RunDir = '@ICINGA2_RUNDIR@' | ||
LocalStateDir = '@CMAKE_INSTALL_FULL_LOCALSTATEDIR@' | ||
PkgDataDir = '@CMAKE_INSTALL_FULL_DATADIR@/icinga2' | ||
IncludeConfDir = '@CMAKE_INSTALL_FULL_DATADIR@/icinga2/include' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Icinga 2 | ||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py COPYONLY) | ||
configure_file(debug.py ${CMAKE_CURRENT_BINARY_DIR}/debug.py COPYONLY) | ||
configure_file(netstring.py ${CMAKE_CURRENT_BINARY_DIR}/netstring.py COPYONLY) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Icinga 2 | ||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from icinga2.utils import netstring | ||
|
||
try: | ||
import json | ||
except ImportError: | ||
import simplejson as json | ||
|
||
class DebugObject: | ||
def __init__(self, obj): | ||
self._obj = obj | ||
|
||
def __str__(self): | ||
return self.format_object() | ||
|
||
def format_object(self): | ||
if self._obj["abstract"]: | ||
result = "Template '" | ||
else: | ||
result = "Object '" | ||
result += self._obj["properties"]["__name"] + "' of type '" + self._obj["type"] + "':\n" | ||
result += self.format_properties(2) | ||
return result | ||
|
||
def format_properties(self, indent=0, path=[]): | ||
props = self._obj["properties"] | ||
for component in path: | ||
props = props[component] | ||
|
||
result = "" | ||
for key, value in props.items(): | ||
if path == [] and key in ['__name', 'type', 'name', 'templates']: | ||
continue | ||
path.append(key) | ||
result += ' ' * indent + "* %s" % (key) | ||
hints = self.format_hints(self, indent + 2, path) | ||
if isinstance(value, dict): | ||
result += "\n" + hints | ||
result += self.format_properties(indent + 2, path) | ||
else: | ||
result += " -> %s\n" % (repr(value)) | ||
result += hints | ||
path.pop() | ||
return result | ||
|
||
def format_hints(self, dhints, indent=0, path=[]): | ||
dhints = self._obj["debug_hints"] | ||
try: | ||
for component in path: | ||
dhints = dhints["properties"][component] | ||
except KeyError: | ||
return "" | ||
|
||
result = "" | ||
for message in dhints["messages"]: | ||
result += ' ' * indent + "%% modified in %s, lines %s:%s-%s:%s\n" % tuple(message[1:]) | ||
return result | ||
|
||
class ObjectsFile: | ||
def __init__(self, file): | ||
self._file = file | ||
|
||
def __iter__(self): | ||
fr = netstring.FileReader(self._file) | ||
|
||
while True: | ||
try: | ||
json_data = fr.readskip() | ||
except EOFError: | ||
break | ||
if json_data == "": | ||
break | ||
yield DebugObject(json.loads(json_data)) |
Oops, something went wrong.