function export nagios services
This commit is contained in:
parent
ce2fd4ad63
commit
602908ab11
@ -1,14 +1,15 @@
|
||||
Facter.add(:disks) do
|
||||
confine :kernel => :linux
|
||||
setcode do
|
||||
disks = []
|
||||
if FileTest.exists?("/proc/partitions")
|
||||
File.readlines("/proc/partitions").each do |str|
|
||||
if str =~ (/(hd|sd).$/)
|
||||
disks.push(str.split(/\s+/)[4])
|
||||
end
|
||||
end
|
||||
end
|
||||
disks.join(",")
|
||||
end
|
||||
confine :kernel => :linux
|
||||
|
||||
setcode do
|
||||
disks = []
|
||||
if FileTest.exists?("/proc/partitions")
|
||||
File.readlines("/proc/partitions").each do |str|
|
||||
if str =~ (/(hd|sd).$/)
|
||||
disks.push(str.split(/\s+/)[4])
|
||||
end
|
||||
end
|
||||
end
|
||||
disks.join(",")
|
||||
end
|
||||
end
|
||||
|
@ -1,14 +1,14 @@
|
||||
Facter.add(:mountpoints) do
|
||||
confine :kernel => :linux
|
||||
setcode do
|
||||
mountpoints = []
|
||||
if FileTest.exists?("/proc/mounts")
|
||||
File.readlines("/proc/mounts").each do |str|
|
||||
if str =~ /(ext2|ext3|ext4|reiserfs|xfs)/
|
||||
mountpoints.push(str.split(/ /)[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
mountpoints.join(",")
|
||||
end
|
||||
confine :kernel => :linux
|
||||
setcode do
|
||||
mountpoints = []
|
||||
if FileTest.exists?("/proc/mounts")
|
||||
File.readlines("/proc/mounts").each do |str|
|
||||
if str =~ /(ext2|ext3|ext4|reiserfs|xfs)/
|
||||
mountpoints.push(str.split(/ /)[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
mountpoints.join(",")
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,30 @@
|
||||
# Parse array and add value to the Puppet resource
|
||||
require 'puppet/parser/functions'
|
||||
|
||||
Puppet::Parser::Functions.newfunction(:nagios_services_export,
|
||||
:type => :statement,
|
||||
:doc => <<-'ENDOFDOC'
|
||||
Create exported nagios_service resourse with array params
|
||||
for examples:
|
||||
|
||||
nagios_services_export( $services, $services_list,
|
||||
{
|
||||
'hostgroup_name' => newgroup,
|
||||
'target' => "/etc/nagios3/services.cfg"
|
||||
})
|
||||
ENDOFDOC
|
||||
) do |vals|
|
||||
type = '@@nagios_service'
|
||||
commands, command_list, params = vals
|
||||
raise(ArgumentError, 'commands must specify and must be an Array') unless commands.kind_of? Array
|
||||
raise(ArgumentError, 'services_list must specify and must be an Hash') unless command_list.kind_of? Hash
|
||||
fqdn = lookupvar('{fqdn}')
|
||||
params ||= {}
|
||||
commands.each { |command|
|
||||
params.merge!({'check_command' => command_list[command],
|
||||
'service_description' => command,
|
||||
'host_name' => lookupvar('fqdn') })
|
||||
Puppet::Parser::Functions.function(:create_resources)
|
||||
function_create_resources([type, { command => params}])
|
||||
}
|
||||
end
|
@ -5,6 +5,24 @@ class nagios::common inherits nagios {
|
||||
nagios::host::hostextinfo { $::hostname: }
|
||||
#nagios::host::hostgroups { $::hostname: }
|
||||
|
||||
if $::virtual == 'physical' {
|
||||
$a_disks = split($::disks, ',')
|
||||
nagios::service::services { $a_disks:
|
||||
}
|
||||
|
||||
$a_interfaces = split($::interfaces, ',')
|
||||
nagios::service::services { $a_interfaces:
|
||||
}
|
||||
}
|
||||
|
||||
## If you use puppet 3.1 or higher use this function instead below code
|
||||
#
|
||||
# nagios_services_export( $services, $services_list,
|
||||
#{
|
||||
# 'hostgroup_name' => $hostgroup,
|
||||
# 'target' => "/etc/${nagios::params::masterdir}/${proj_name}/${::hostname}_services.cfg"
|
||||
#})
|
||||
|
||||
define runservice($service) {
|
||||
include nagios::params
|
||||
notify {$services_list[$service]:}
|
||||
@ -31,14 +49,4 @@ class nagios::common inherits nagios {
|
||||
}
|
||||
|
||||
nagios::common::addservice { 'Add services': }
|
||||
|
||||
if $::virtual == 'physical' {
|
||||
$a_disks = split($::disks, ',')
|
||||
nagios::service::services { $a_disks:
|
||||
}
|
||||
|
||||
$a_interfaces = split($::interfaces, ',')
|
||||
nagios::service::services { $a_interfaces:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user