]> granicus.if.org Git - icinga2/blob - tools/icinga2-forget-agent.cmake
Make sure that icinga2-forget-agent removes the .peer file.
[icinga2] / tools / icinga2-forget-agent.cmake
1 #!/usr/bin/env python
2 # Icinga 2
3 # Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 from __future__ import print_function
20 import sys, os, hashlib
21
22 def warning(*objs):
23     print(*objs, file=sys.stderr)
24
25 if len(sys.argv) < 2:
26     warning("Syntax: %s <identity>" % (sys.argv[0]))
27     sys.exit(1)
28
29 cn = sys.argv[1]
30
31 inventory_file = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/agent/inventory/" + hashlib.sha256(cn).hexdigest()
32
33 if not os.path.isfile(inventory_file):
34     warning("There's no inventory file for agent '%s'." % (cn))
35     sys.exit(0)
36
37 os.unlink(inventory_file)
38
39 peer_file = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/agent/inventory/" + hashlib.sha256(cn).hexdigest() + ".peer"
40
41 if os.path.isfile(peer_file):
42     os.unlink(peer_file)
43
44 print("Inventory information has been removed for agent '%s'." % (cn))
45 sys.exit(0)