Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Puppet::Parser::Functions
- newfunction(:nagios_rdiff_backup_config) do |args|
- module NagiosCommonTop
- return if lookupvar('config_path').empty?
- hostname = lookupvar('long_name')
- #generate nagios rdiff backup monitoring config file
- service_definition = '# Do not modify this file by hand; it is automatically generated by Puppet.
- # Any changes you make here will be over-written by Puppet on its next run.
- '
- nagios_host = `grep 'host_name #{hostname}' #{lookupvar('config_path')}../hosts/hosts.cfg | grep -v ^#`
- end
- include NagiosCommonTop
- if nagios_host.empty? then
- service_definition += "
- # This host is not currently being monitored by nagios
- # To enable this service monitor, add the host to
- # #{lookupvar('config_path')}../hosts/hosts.cfg
- "
- else
- service_definition += "
- define service {
- use generic-service
- hosts "+hostname+"
- service_description New backed-up files
- check_command check_rdiff_backup_age!2
- }
- "
- end
- service_definition = service_definition.gsub(/^\t+/, '') #remove ugly leading tabs
- service_definition = service_definition.gsub(/^ /, "\t") #replace leading spaces with tabs
- original_config = ''
- begin
- on_disk = File.open(lookupvar('config_path') + hostname + '_rdiff_backup.cfg', File::RDONLY)
- original_config = on_disk.readlines.join
- rescue
- #we don't care if it fails, because "original_file" will already be empty
- end
- if original_config != service_definition
- File.open(lookupvar('config_path') + hostname + '_rdiff_backup.cfg', 'w') do |fd|
- fd.puts service_definition
- end
- #we won't check for error handling here, because there's nothing we can do about it if it fails
- end
- end
- end
Add Comment
Please, Sign In to add comment