Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.29 KB | None | 0 0
  1. class nagios
  2. {
  3. define service($args = "", $command = false) {
  4. @@nagios_service { "${title}_${hostname}":
  5. check_command => $command ? {
  6. false => "${title}!${args}",
  7. default => "${command}!${args}"
  8. },
  9. use => "generic-service",
  10. host_name => "$fqdn",
  11. notification_period => "24x7",
  12. service_description => "${hostname}_${title}";
  13. }
  14. }
  15. }
  16.  
  17. class nagios::target
  18. {
  19. package { nagios-plugins: ensure => latest }
  20.  
  21. $packages = [ nagios-nrpe, nagios-plugins-all ]
  22.  
  23. package { $packages:
  24. ensure => latest,
  25. require => Package[nagios-plugins];
  26. }
  27.  
  28. firewall::rule { nagios-nrpe: module => "nagios" }
  29.  
  30. file { "/etc/nagios":
  31. owner => "root",
  32. group => "root",
  33. mode => 0755,
  34. type => directory,
  35. ensure => directory;
  36. }
  37.  
  38. file { "/etc/nagios/nrpe":
  39. owner => "root",
  40. group => "root",
  41. mode => 0755,
  42. type => directory,
  43. ensure => directory,
  44. require => File["/etc/nagios"];
  45. }
  46.  
  47. $plugin_dir = $architecture ? {
  48. "x86_64" => "/usr/lib64/nagios/plugins",
  49. "i386" => "/usr/lib/nagios/plugins"
  50. }
  51.  
  52. @file { "$plugin_dir/check_service":
  53. owner => "root",
  54. group => "root",
  55. mode => 0755,
  56. ensure => present,
  57. source => "puppet:///modules/nagios/check_service",
  58. require => Package[nagios-nrpe],
  59. tag => "nagios_checks";
  60. }
  61.  
  62. @file { "$plugin_dir/check_mem":
  63. owner => "root",
  64. group => "root",
  65. mode => 0755,
  66. ensure => present,
  67. source => "puppet:///modules/nagios/check_mem",
  68. require => Package[nagios-nrpe],
  69. tag => "nagios_checks";
  70. }
  71.  
  72. File <| tag == "nagios_checks" |>
  73. File <| title == "/var/run/supervisor.sock" |>
  74.  
  75. define service() {
  76. $plugin_dir = $architecture ? {
  77. "x86_64" => "/usr/lib64/nagios/plugins",
  78. "i386" => "/usr/lib/nagios/plugins"
  79. }
  80.  
  81. nagios::target::command { "check_$title":
  82. command => "$plugin_dir/check_service -s $title";
  83. }
  84. }
  85.  
  86. define monitor($max_procs_warn = 150, $max_procs_crit = 200,
  87. $root_volume = "/dev/mapper/VolGroup00-LogVol00") {
  88. $plugin_dir = $architecture ? {
  89. "x86_64" => "/usr/lib64/nagios/plugins",
  90. "i386" => "/usr/lib/nagios/plugins"
  91. }
  92.  
  93. file { "nrpe.cfg for $title":
  94. name => "/etc/nagios/nrpe.cfg",
  95. owner => "root",
  96. group => "root",
  97. mode => 0644,
  98. ensure => present,
  99. content => template("nagios/nrpe.cfg.erb"),
  100. notify => Service[nrpe],
  101. require => Package[nagios-nrpe];
  102. }
  103. }
  104.  
  105. define command($command) {
  106. include nagios::target
  107.  
  108. file { "/etc/nagios/nrpe/$title.cfg":
  109. owner => "root",
  110. group => "root",
  111. mode => 0755,
  112. ensure => present,
  113. content => "command[$title]=$command\n",
  114. notify => Service[nrpe],
  115. require => File["/etc/nagios/nrpe"];
  116. }
  117.  
  118. nagios::service { "$title":
  119. command => "check_nrpe",
  120. args => "$title";
  121. }
  122. }
  123.  
  124. service { nrpe:
  125. ensure => running,
  126. hasstatus => true,
  127. hasrestart => true,
  128. enable => true,
  129. require => [ Package[nagios-nrpe],
  130. File["/etc/nagios/nrpe"] ];
  131. }
  132.  
  133. @@nagios_host { $fqdn:
  134. use => "linux-server",
  135. alias => $hostname,
  136. # jww (2009-05-02): explicit host references!
  137. address => $hostname ? {
  138. "abc-p1-srv-1" => "$ipaddress_eth1",
  139. "abc-p1-srv-2" => "$ipaddress_eth1",
  140. default => "$ipaddress"
  141. },
  142. ensure => present;
  143. }
  144.  
  145. nagios::service { check_ping:
  146. args => "100.0,20%!500.0,60%";
  147. }
  148. nagios::service { check_load:
  149. command => "check_nrpe",
  150. args => "check_load";
  151. }
  152. nagios::service { check_zombie_procs:
  153. command => "check_nrpe",
  154. args => "check_zombie_procs";
  155. }
  156. nagios::service { check_total_procs:
  157. command => "check_nrpe",
  158. args => "check_total_procs";
  159. }
  160.  
  161. nagios::target::command { "check_mem":
  162. command => "$plugin_dir/check_mem -w 15 -c 5",
  163. }
  164. nagios::target::command { "check_swap":
  165. command => "$plugin_dir/check_swap -w 75 -c 50",
  166. }
  167. }
  168.  
  169. class nagios::monitor
  170. {
  171. include apache
  172.  
  173. $packages = [ nagios, nagios-plugins-nrpe ]
  174.  
  175. package { $packages: ensure => latest }
  176.  
  177. cron { "nagios":
  178. ensure => present,
  179. command => "/sbin/service nagios restart > /dev/null",
  180. user => "root",
  181. hour => 4,
  182. minute => 0;
  183. }
  184.  
  185. file { "/etc/nagios/nagios_host.cfg":
  186. owner => "nagios",
  187. group => "nagios",
  188. mode => 0640,
  189. ensure => present,
  190. notify => Service[nagios],
  191. require => Package[nagios];
  192. }
  193.  
  194. file { "/etc/nagios/nagios_service.cfg":
  195. owner => "nagios",
  196. group => "nagios",
  197. mode => 0640,
  198. ensure => present,
  199. notify => Service[nagios],
  200. require => Package[nagios];
  201. }
  202.  
  203. file { "/etc/nagios/nagios.cfg":
  204. owner => "nagios",
  205. group => "nagios",
  206. mode => 0664,
  207. ensure => present,
  208. content => template("nagios/nagios.cfg.erb"),
  209. notify => Service[nagios],
  210. require => Package[nagios];
  211. }
  212.  
  213. file { "/etc/nagios/command-plugins.cfg":
  214. owner => "root",
  215. group => "root",
  216. mode => 0644,
  217. ensure => present,
  218. source => $architecture ? {
  219. "x86_64" => "puppet:///modules/nagios/command-plugins.cfg",
  220. "i386" => "puppet:///modules/nagios/command-plugins_i386.cfg"
  221. },
  222. notify => Service[nagios],
  223. require => Package[nagios-plugins];
  224. }
  225.  
  226. file { "/etc/nagios/objects":
  227. owner => "root",
  228. group => "root",
  229. mode => 0755,
  230. type => directory,
  231. ensure => directory,
  232. require => [ Package[nagios],
  233. Package[nagios-plugins] ];
  234. }
  235.  
  236. file { "/etc/nagios/objects/commands.cfg":
  237. owner => "nagios",
  238. group => "nagios",
  239. mode => 0664,
  240. ensure => present,
  241. source => "puppet:///modules/nagios/objects/commands.cfg",
  242. notify => Service[nagios],
  243. require => File["/etc/nagios/objects"];
  244. }
  245.  
  246. file { "/etc/nagios/cgi.cfg":
  247. owner => "nagios",
  248. group => "nagios",
  249. mode => 0664,
  250. ensure => present,
  251. content => template("nagios/cgi.cfg.erb"),
  252. notify => Service[nagios],
  253. require => Package[nagios];
  254. }
  255.  
  256. service { nagios:
  257. ensure => running,
  258. enable => true,
  259. hasstatus => true,
  260. hasrestart => true,
  261. require => Package[nagios];
  262. }
  263.  
  264. exec { "created nagiosadmin auth info":
  265. user => "root",
  266. command => "/usr/bin/htpasswd -b -c /etc/nagios/htpasswd.users nagiosadmin nagiosadmin",
  267. creates => "/etc/nagios/htpasswd.users",
  268. notify => Service[httpd],
  269. require => Package[httpd];
  270. }
  271.  
  272. file { "/etc/nagios/htpasswd.users":
  273. owner => "root",
  274. group => "apache",
  275. mode => 0640,
  276. ensure => present,
  277. require => Exec["created nagiosadmin auth info"];
  278. }
  279.  
  280. file { "/var/nagios/rw/nagios.cmd":
  281. owner => "nagios",
  282. group => "apache",
  283. mode => 0660,
  284. ensure => present,
  285. subscribe => Service[nagios],
  286. require => [ Service[nagios], Package[httpd] ];
  287. }
  288.  
  289. # collect resources and populate /etc/nagios/nagios_*.cfg
  290. Nagios_host <<||>>
  291. Nagios_service <<||>>
  292.  
  293. nagios::service { check_nagios:
  294. args => "5!/var/nagios/status.dat!/usr/bin/nagios" }
  295.  
  296. selinux::policy { nagios-ext: module => "nagios" }
  297. }
  298.  
  299. class nagios::ndoutils inherits nagios::monitor
  300. {
  301. include postgres
  302.  
  303. $packages = [ ndoutils, perl-DBD-Pg ]
  304.  
  305. package { $packages:
  306. ensure => installed,
  307. require => Package[nagios];
  308. }
  309.  
  310. postgres::database { "nagios":
  311. user => "nagios",
  312. password => "nagios";
  313. }
  314.  
  315. exec { "initialize nagios database":
  316. user => "postgres",
  317. timeout => 120,
  318. command => "/bin/cat /usr/share/ndoutils/postgresql/ndoutils.psql | /bin/grep -v '^DROP' | /usr/bin/psql -U nagios",
  319. refreshonly => true,
  320. require => [ Postgres::Database[nagios], Package[ndoutils] ];
  321. }
  322.  
  323. file { "/etc/nagios/ndo2db.cfg":
  324. owner => "nagios",
  325. group => "nagios",
  326. mode => 0644,
  327. ensure => present,
  328. source => "puppet:///modules/nagios/ndo2db.cfg",
  329. notify => Service[ndoutils],
  330. require => Package[ndoutils];
  331. }
  332.  
  333. service { ndoutils:
  334. ensure => running,
  335. hasstatus => true,
  336. hasrestart => true,
  337. enable => true,
  338. notify => Service[nagios],
  339. require => Exec["initialize nagios database"];
  340. }
  341.  
  342. Service[nagios] {
  343. require => Service[ndoutils]
  344. }
  345. }
Add Comment
Please, Sign In to add comment