summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Munin.hs
blob: 6dab25ef32db657a6858690371d19efc4f785372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
-- | Maintainer: Jelmer Vernooij <jelmer@jelmer.uk>
--
module Propellor.Property.Munin (
	hostListFragment,
	hostListFragment',
	nodePort,
	nodeInstalled,
	nodeRestarted,
	nodeConfPath,
	masterInstalled,
	masterRestarted,
	masterConfPath,
) where

import Propellor
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service

nodePort :: Integer
nodePort = 4949

nodeInstalled :: Property DebianLike
nodeInstalled = Apt.serviceInstalledRunning "munin-node"

nodeRestarted :: Property DebianLike
nodeRestarted = Service.restarted "munin-node"

nodeConfPath :: FilePath
nodeConfPath = "/etc/munin/munin-node.conf"

masterInstalled :: Property DebianLike
masterInstalled = Apt.serviceInstalledRunning "munin"

masterRestarted :: Property DebianLike
masterRestarted = Service.restarted "munin"

masterConfPath :: FilePath
masterConfPath = "/etc/munin/munin.conf"


-- | Create the host list fragment for master config.
-- Takes an optional override list for hosts that are accessible on a non-standard host/port.
-- TODO(jelmer): Only do this on hosts where munin is present (in other words, with Munin.installedNode)
hostListFragment' :: [Host] -> [(HostName, (IPAddr, Port))] -> [String]
hostListFragment' hs os = concatMap muninHost hs
  where
	muninHost :: Host -> [String]
	muninHost h = [ "[" ++ (hostName h) ++ "]"
		      , "  address " ++ maybe (hostName h) (val . fst) (hOverride h)
		      ] ++ (maybe [] (\x -> ["  port " ++ (val $ snd x)]) (hOverride h)) ++ [""]
	hOverride :: Host -> Maybe (IPAddr, Port)
	hOverride h = lookup (hostName h) os

-- | Create the host list fragment for master config.
hostListFragment :: [Host] -> [String]
hostListFragment hs = hostListFragment' hs []