~benji/charms/precise/juju-gui/bug-1284088

« back to all changes in this revision

Viewing changes to scripts/charmsupport/nrpe.py

  • Committer: Benji York
  • Date: 2014-03-19 19:36:37 UTC
  • Revision ID: benji@benjiyork.com-20140319193637-vh9rhvsnzmt3xzan
fix bugs found in review

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
        subprocess.call(['juju-log', 'Check command not found: {}'.format(command[0])])
111
111
        return ''
112
112
 
113
 
    def service_file_name(self, nagios_context, hostname):
 
113
    def service_file_name(self, hostname):
114
114
        return '{}/service__{}_check_{}.cfg'.format(
115
115
            NRPE.nagios_exportdir, hostname, self.shortname)
116
116
 
127
127
            'shortname': self.shortname,
128
128
        }
129
129
        nrpe_service_text = Check.service_template.format(**templ_vars)
130
 
        nrpe_service_file = '{}/service__{}_check_{}.cfg'.format(
131
 
            NRPE.nagios_exportdir, hostname, self.shortname)
132
 
        nrpe_service_file = self.service_file_name(nagios_context, hostname)
 
130
        nrpe_service_file = self.service_file_name(hostname)
133
131
        with open(nrpe_service_file, 'w') as nrpe_service_config:
134
132
            nrpe_service_config.write(str(nrpe_service_text))
135
133
 
139
137
            nrpe_check_config.write("command[check_{}]={}\n".format(
140
138
                self.shortname, self.check_cmd))
141
139
 
142
 
    def remove(self, nagios_context, hostname):
 
140
    def remove(self, hostname):
143
141
        """Remove the configuration file for this check."""
144
142
        try:
145
 
            os.unlink(self.service_file_name(nagios_context, hostname))
 
143
            os.unlink(self.service_file_name(hostname))
146
144
        except OSError, e:
147
145
            if e.errno == errno.ENOENT:
148
146
                # Ignore the fact that the file didn't exist.
193
191
 
194
192
    def remove_checks(self):
195
193
        for check in self.checks:
196
 
            check.remove(self.nagios_context, self.hostname)
 
194
            check.remove(self.hostname)