25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'manifests/init.pp', line 25
class ccs_monit (
Variant[String,Array[String]] $mailhost = 'localhost',
Variant[String,Array[String]] $alert = 'root@localhost',
String $pkgurl = 'https://example.org',
String $pkgurl_user = 'someuser',
String $pkgurl_pass = 'somepass',
Boolean $uptime = true,
Boolean $gpfs = false,
Array[String] $hosts = [],
Boolean $temp = false,
Boolean $network = true,
) {
ensure_packages(['monit', 'freeipmi'])
## Not sure if monit creates this...
file { '/var/monit':
ensure => directory,
}
## Change check interval from 30s to 5m.
## TODO? add "read-only" to the allow line?
file_line { 'Change monit interval':
path => '/etc/monitrc',
match => '^set daemon',
line => 'set daemon 300 # check services at 300 seconds intervals',
notify => Service['monit'],
}
$monitd = '/etc/monit.d'
if $alert =~ String {
$alerts = [$alert]
} else {
$alerts = $alert
}
if $mailhost =~ Array {
$mailhosts = join($mailhost, ', ')
} else {
$mailhosts = $mailhost
}
$alertfile = 'alert'
file { "${monitd}/${alertfile}":
ensure => file,
content => epp(
"${title}/${alertfile}.epp",
{ 'mailhost' => $mailhosts, 'alerts' => $alerts }
),
notify => Service['monit'],
}
$config = 'config'
file { "${monitd}/${config}":
ensure => file,
source => "puppet:///modules/${title}/${config}",
notify => Service['monit'],
}
## system:
## Note that the use of "per core" requires monit >= 5.26.
## As of 2019/09, the epel7 version is 5.25.
## This requires us to install a newer version in /usr/local/bin,
## and modify the service file, but it does mean the config file can
## be identical for all hosts.
## swap warning is not very useful, since Linux doesn't usually free swap.
## Maybe it should just be removed?
##
## We are using uptime to detect reboots. It also alerts on success.
## This could be suppressed with:
## else if succeeded exec "/bin/false"
## but that means uptime is always in failed state.
$system = 'system'
file { "${monitd}/${system}":
ensure => file,
content => epp("${title}/${system}.epp", { 'uptime' => $uptime }),
notify => Service['monit'],
}
## Ignoring: /boot, and in older slac installs: /scswork, /usr/vice/cache.
## vi do not have separate /tmp.
## dc nodes have /data.
## Older installs have separate /opt /scratch /var.
## Newer ones have /home instead.
## TODO loop over mount points instead?
## Can also do IO rates.
$disks = {
'root' => '/',
'tmp' => '/tmp',
'home' => '/home',
'data' => '/data',
'opt' => '/opt',
'var' => '/var',
'scratch' => '/scratch',
'lsst-ir2db01' => '/lsst-ir2db01',
}.filter|$key,$value| { $facts['mountpoints'][$value] }
$disk = 'disks'
file { "${monitd}/${disk}":
ensure => file,
content => epp("${title}/${disk}.epp", { 'disks' => $disks }),
notify => Service['monit'],
}
## Alert if a client loses gpfs.
if $facts['native_gpfs'] == 'true' {
$gpfse = 'gpfs-exists'
file { "${monitd}/${gpfse}":
ensure => file,
source => "puppet:///modules/${title}/${gpfse}",
notify => Service['monit'],
}
}
## Check gpfs capacity.
if $gpfs {
$gpfsf = 'gpfs'
file { "${monitd}/${gpfsf}":
ensure => file,
source => "puppet:///modules/${title}/${gpfsf}",
notify => Service['monit'],
}
}
unless empty($hosts) {
$hfile = 'hosts'
file { "${monitd}/${hfile}":
ensure => file,
content => epp("${title}/${hfile}.epp", { 'hosts' => $hosts }),
notify => Service['monit'],
}
}
if $temp {
$itemp = 'inlet-temp'
file { "${monitd}/${itemp}":
ensure => file,
source => "puppet:///modules/${title}/${itemp}",
notify => Service['monit'],
}
$etemp = 'monit_inlet_temp'
file { "/usr/local/bin/${etemp}":
ensure => file,
source => "puppet:///modules/${title}/${etemp}",
mode => '0755',
notify => Service['monit'],
}
}
## TODO try to automatically fix netspeed?
## We disable this on virt hosts.
if $network and !fact('is_virtual') {
$main_interface = fact('networking.primary')
$nfile = 'network'
file { "${monitd}/${nfile}":
ensure => file,
content => epp(
"${title}/${nfile}.epp",
{ 'interface' => $main_interface }
),
notify => Service['monit'],
}
}
$netspeed = 'monit_netspeed'
file { "/usr/local/bin/${netspeed}":
ensure => file,
source => "puppet:///modules/${title}/${netspeed}",
mode => '0755',
}
if fact('has_dellperc') {
$hwraidf = 'hwraid'
file { "${monitd}/${hwraidf}":
ensure => file,
source => "puppet:///modules/${title}/${hwraidf}",
notify => Service['monit'],
}
## Needs the raid utility (eg perccli64) to be installed.
$hexe = 'monit_hwraid'
file { "/usr/local/bin/${hexe}":
ensure => file,
source => "puppet:///modules/${title}/${hexe}",
mode => '0755',
}
}
service { 'monit':
ensure => running,
enable => true,
}
}
|