~gnuoy/charms/trusty/nrpe-external-master/services-framework

« back to all changes in this revision

Viewing changes to hooks/nrpe_helpers.py

  • Committer: Liam Young
  • Date: 2015-03-22 15:20:27 UTC
  • Revision ID: liam.young@canonical.com-20150322152027-jfd4cw34a27f8u6p
Add doc strings

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
        return self.principle_relation.is_ready()
19
19
 
20
20
    def convert_local_checks(self, monitors, monitor_src):
 
21
        """ Convert check from local checks to remote nrpe checks
 
22
 
 
23
        monitors -- monitor dict
 
24
        monitor_src -- Monitor source principle, subordinate or user
 
25
        """
21
26
        mons = {}
22
27
        for checktype in monitors.keys():
23
28
            for checkname in monitors[checktype]:
31
36
        return mons
32
37
 
33
38
    def get_subordinate_monitors(self):
 
39
        """ Return default monitors defined by this charm """
34
40
        monitors = {
35
41
            'monitors': {
36
42
                'remote': {
44
50
        return monitors
45
51
 
46
52
    def get_user_defined_monitors(self):
 
53
        """ Return monitors defined by monitors config option """
47
54
        return yaml.safe_load(hookenv.config('monitors'))
48
55
 
49
56
    def get_principle_monitors(self):
 
57
        """ Return monitors passed by relation with principle """
50
58
        return self.principle_relation.get_monitors()
51
59
 
52
60
    def get_monitor_dicts(self):
 
61
        """ Return all monitor dicts """
53
62
        monitor_dicts = {
54
63
            'principle': self.get_principle_monitors(),
55
64
            'subordinate': self.get_subordinate_monitors(),
58
67
        return monitor_dicts
59
68
 
60
69
    def get_monitors(self):
 
70
        """ Return monitor dict of all monitors merged together and local
 
71
            monitors converted to remote nrpe checks
 
72
        """
61
73
        monitors = {
62
74
            'monitors': {
63
75
                'remote': {
91
103
        return monitors
92
104
 
93
105
    def get_data(self):
94
 
        """ Context for rendering an nrpe config file """
95
106
        super(MonitorsRelation, self).get_data()
96
107
        if not hookenv.relation_ids(self.name):
97
108
            return
126
137
        return '__unit__' in self[self.name][0]
127
138
 
128
139
    def nagios_hostname(self):
 
140
        """ Return the string that nagios will use to identify this host """
129
141
        host_context = hookenv.config('nagios_host_context')
130
142
        hostname_type = hookenv.config('nagios_hostname_type')
131
143
        if hostname_type == 'host' or not self.is_ready():
137
149
            return nagios_hostname
138
150
 
139
151
    def get_monitors(self):
 
152
        """ Return monitors passed by principle charm """
140
153
        if not self.is_ready():
141
154
            return
142
155
        if 'monitors' in self[self.name][0]:
167
180
 
168
181
 
169
182
class NRPECheckCtxt(dict):
170
 
 
 
183
    """ Convert a local monitor definition into dict needed for writting the
 
184
        nrpe check definition
 
185
    """
171
186
    def __init__(self, checktype, check_opts, monitor_src):
172
187
        plugin_path = '/usr/lib/nagios/plugins'
173
188
        if checktype == 'procrunning':