File: remove_empty_configfiles.py

package info (click to toggle)
pynag 1.1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,324 kB
  • sloc: python: 9,792; makefile: 200
file content (23 lines) | stat: -rw-r--r-- 779 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
#
# This script looks for files in your configuration that have no objects in them.
#
#
from __future__ import absolute_import
from __future__ import print_function
import os
import pynag.Model

# Load pynag cache
all_objects = pynag.Model.ObjectDefinition.objects.all

for i in pynag.Model.config.get_cfg_files():
    objects = pynag.Model.ObjectDefinition.objects.filter(filename=i)
    if len(objects) == 0: # No objects found in that file
        # Objects defined via cfg_file= should not be removed because nagios will not reload
        # after you remove the file
        for k,v, in pynag.Model.config.maincfg_values:
            if k == 'cfg-file' and v == i:
                continue
        print("Empty config file: %s" % i)
        # os.remove(i)