@ -6,31 +6,39 @@ let
cfg = config . services . smokeping ;
smokepingHome = " / v a r / l i b / s m o k e p i n g " ;
smokepingPidDir = " / r u n " ;
configFile = ''
* * * General * * *
owner = $ { cfg . owner }
contact = $ { cfg . ownerEmail }
mailhost = $ { cfg . mailHost }
#sendmail = /var/setuid-wrappers/sendmail
imgcache = $ { smokepingHome } /cache
imgurl = http://$ { cfg . hostName }: $ { builtins . toString cfg . port } /cache
datadir = $ { smokepingHome } /data
piddir = $ { smokepingPidDir }
cgiurl = http://$ { cfg . hostName }: $ { builtins . toString cfg . port } /smokeping.cgi
smokemail = $ { cfg . smokeMailTemplate }
* * * Presentation * * *
template = $ { cfg . presentationTemplate }
$ { cfg . presentationConfig }
#*** Alerts ***
#${cfg.alertConfig}
* * * Database * * *
$ { cfg . databaseConfig }
* * * Probes * * *
$ { cfg . probeConfig }
* * * Targets * * *
$ { cfg . targetConfig }
$ { cfg . extraConfig }
'' ;
configFile =
if cfg . config == null
then
''
* * * General * * *
owner = $ { cfg . owner }
contact = $ { cfg . ownerEmail }
$ { lib . optionalString ( cfg . mailHost != " " ) " m a i l h o s t = ${ cfg . mailHost } " }
$ { lib . optionalString ( cfg . sendmail != null ) " s e n d m a i l = ${ cfg . sendmail } " }
imgcache = $ { smokepingHome } /cache
imgurl = http://$ { cfg . hostName }: $ { builtins . toString cfg . port } /cache
datadir = $ { smokepingHome } /data
pagedir = $ { smokepingHome } /cache
piddir = $ { smokepingPidDir }
cgiurl = http://$ { cfg . hostName }: $ { builtins . toString cfg . port } /smokeping.cgi
linkstyle = $ { cfg . linkStyle }
smokemail = $ { cfg . smokeMailTemplate }
* * * Presentation * * *
template = $ { cfg . presentationTemplate }
$ { cfg . presentationConfig }
* * * Alerts * * *
$ { cfg . alertConfig }
* * * Database * * *
$ { cfg . databaseConfig }
* * * Probes * * *
$ { cfg . probeConfig }
* * * Targets * * *
$ { cfg . targetConfig }
$ { cfg . extraConfig }
''
else
cfg . config ;
configPath = pkgs . writeText " s m o k e p i n g . c o n f " configFile ;
cgiHome = pkgs . writeScript " s m o k e p i n g . f c g i " ''
#!${pkgs.bash}/bin/bash
@ -59,8 +67,15 @@ in
} ;
mailHost = mkOption {
type = types . string ;
default = " 1 2 7 . 0 . 0 . 1 " ;
description = " U s e t h i s S M T P s e r v e r r a t h e r t h a n l o c a l h o s t " ;
default = " " ;
example = " l o c a l h o s t " ;
description = " U s e t h i s S M T P s e r v e r t o s e n d a l e r t s " ;
} ;
sendmail = mkOption {
type = types . nullOr types . path ;
default = null ;
example = " / v a r / s e t u i d - w r a p p e r s / s e n d m a i l " ;
description = " U s e t h i s s e n d m a i l c o m p a t i b l e s c r i p t t o d e l i v e r a l e r t s " ;
} ;
smokeMailTemplate = mkOption {
type = types . string ;
@ -71,6 +86,7 @@ in
package = mkOption {
type = types . package ;
default = pkgs . smokeping ;
defaultText = " p k g s . s m o k e p i n g " ;
description = " S p e c i f y a c u s t o m s m o k e p i n g p a c k a g e " ;
} ;
owner = mkOption {
@ -85,6 +101,12 @@ in
example = " s o m e w h e r e . e x a m p l e . c o m " ;
description = " D N S n a m e f o r t h e u r l s g e n e r a t e d i n t h e c g i . " ;
} ;
linkStyle = mkOption {
type = types . enum [ " o r i g i n a l " " a b s o l u t e " " r e l a t i v e " ] ;
default = " r e l a t i v e " ;
example = " a b s o l u t e " ;
description = " D N S n a m e f o r t h e u r l s g e n e r a t e d i n t h e c g i . " ;
} ;
port = mkOption {
type = types . int ;
default = 8081 ;
@ -132,7 +154,10 @@ in
} ;
alertConfig = mkOption {
type = types . string ;
default = " " ;
default = ''
to = root @ localhost
from = smokeping @ localhost
'' ;
example = literalExample ''
to = alertee @ address . somewhere
from = smokealert @ company . xy
@ -223,12 +248,26 @@ in
default = " " ;
description = " A n y a d d i t i o n a l c u s t o m i z a t i o n n o t a l r e a d y i n c l u d e d . " ;
} ;
config = mkOption {
type = types . nullOr types . string ;
default = null ;
description = " F u l l s m o k e p i n g c o n f i g s u p p l i e d b y t h e u s e r . O v e r r i d e s " +
" a n d r e p l a c e s a n y o t h e r c o n f i g u r a t i o n s u p p l i e d . " ;
} ;
} ;
} ;
config = mkIf cfg . enable {
assertions = [
{
assertion = ! ( cfg . sendmail != null && cfg . mailHost != " " ) ;
message = " s e r v i c e s . s m o k e p i n g : s e n d m a i l a n d M a i l h o s t c a n n o t b o t h b e e n a b l e d . " ;
}
] ;
security . setuidPrograms = [ " f p i n g " ] ;
environment . systemPackages = [ pkgs . fping ] ;
users . extraUsers = singleton {
name = cfg . user ;
isNormalUser = false ;
@ -243,9 +282,12 @@ in
serviceConfig . PermissionsStartOnly = true ;
preStart = ''
mkdir - m 0755 - p $ { smokepingHome } /cache $ { smokepingHome } /data
rm - f $ { smokepingHome } /cropper
ln - s $ { cfg . package } /htdocs/cropper $ { smokepingHome } /cropper
chown - R $ { cfg . user } $ { smokepingHome }
cp $ { cgiHome } $ { smokepingHome } /smokeping.fcgi
$ { cfg . package } /bin/smokeping - - check - - config = $ { configPath }
$ { cfg . package } /bin/smokeping - - static - - config = $ { configPath }
'' ;
script = '' ${ cfg . package } / b i n / s m o k e p i n g - - c o n f i g = ${ configPath } - - n o d a e m o n '' ;
} ;
@ -253,8 +295,9 @@ in
wantedBy = [ " m u l t i - u s e r . t a r g e t " ] ;
requires = [ " s m o k e p i n g . s e r v i c e " ] ;
partOf = [ " s m o k e p i n g . s e r v i c e " ] ;
path = with pkgs ; [ bash rrdtool smokeping ] ;
script = '' ${ pkgs . thttpd } / b i n / t h t t p d - u ${ cfg . user } - c " * * . f c g i " - d ${ smokepingHome } - p ${ builtins . toString cfg . port } - D '' ;
path = with pkgs ; [ bash rrdtool smokeping thttpd ] ;
script = '' t h t t p d - u ${ cfg . user } - c " * * . f c g i " - d ${ smokepingHome } - p ${ builtins . toString cfg . port } - D - n o s '' ;
serviceConfig . Restart = " a l w a y s " ;
} ;
} ;
}