monitoring.scm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.org>
  3. ;;; Copyright © 2018, 2019 Gábor Boskovits <boskovits@gmail.com>
  4. ;;; Copyright © 2018, 2019, 2020 Oleg Pykhalov <go.wigust@gmail.com>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (gnu services monitoring)
  21. #:use-module (gnu services)
  22. #:use-module (gnu services configuration)
  23. #:use-module (gnu services shepherd)
  24. #:use-module (gnu services web)
  25. #:use-module (gnu packages admin)
  26. #:use-module (gnu packages monitoring)
  27. #:use-module (gnu system shadow)
  28. #:use-module (guix gexp)
  29. #:use-module (guix packages)
  30. #:use-module (guix records)
  31. #:use-module (guix utils)
  32. #:use-module ((guix ui) #:select (display-hint G_))
  33. #:use-module (ice-9 match)
  34. #:use-module (ice-9 rdelim)
  35. #:use-module (srfi srfi-26)
  36. #:use-module (srfi srfi-35)
  37. #:export (darkstat-configuration
  38. darkstat-service-type
  39. prometheus-node-exporter-configuration
  40. prometheus-node-exporter-configuration?
  41. prometheus-node-exporter-configuration-package
  42. prometheus-node-exporter-web-listen-address
  43. prometheus-node-exporter-service-type
  44. zabbix-server-configuration
  45. zabbix-server-service-type
  46. zabbix-agent-configuration
  47. zabbix-agent-service-type
  48. zabbix-front-end-configuration
  49. zabbix-front-end-service-type
  50. %zabbix-front-end-configuration-nginx))
  51. ;;;
  52. ;;; darkstat
  53. ;;;
  54. (define-record-type* <darkstat-configuration>
  55. darkstat-configuration make-darkstat-configuration darkstat-configuration?
  56. (package darkstat-configuration-package
  57. (default darkstat))
  58. (interface darkstat-configuration-interface)
  59. (port darkstat-configuration-port
  60. (default "667"))
  61. (bind-address darkstat-configuration-bind-address
  62. (default "127.0.0.1"))
  63. (base darkstat-configuration-base
  64. (default "/")))
  65. (define %darkstat-accounts
  66. (list (user-account
  67. (name "darkstat")
  68. (group "darkstat")
  69. (system? #t)
  70. (comment "darkstat daemon user")
  71. (home-directory "/var/lib/darkstat")
  72. (shell (file-append shadow "/sbin/nologin")))
  73. (user-group
  74. (name "darkstat")
  75. (system? #t))))
  76. (define darkstat-shepherd-service
  77. (match-lambda
  78. (($ <darkstat-configuration>
  79. package interface port bind-address base)
  80. (shepherd-service
  81. (documentation "Network statistics gatherer.")
  82. (provision '(darkstat))
  83. (requirement '(networking))
  84. (start #~(make-forkexec-constructor
  85. (list #$(file-append package "/sbin/darkstat")
  86. "-i" #$interface
  87. "-p" #$port
  88. "-b" #$bind-address
  89. "--base" #$base
  90. "--syslog" "--no-daemon"
  91. "--chroot" "/var/lib/darkstat"
  92. "--user" "darkstat"
  93. "--import" "darkstat.db"
  94. "--export" "darkstat.db")))
  95. (stop #~(make-kill-destructor))))))
  96. (define darkstat-service-type
  97. (service-type
  98. (name 'darkstat)
  99. (description
  100. "Run @command{darkstat} to serve network traffic statistics reports over
  101. HTTP.")
  102. (extensions
  103. (list (service-extension account-service-type
  104. (const %darkstat-accounts))
  105. (service-extension shepherd-root-service-type
  106. (compose list darkstat-shepherd-service))))))
  107. ;;;
  108. ;;; Prometheus node exporter
  109. ;;;
  110. (define-record-type* <prometheus-node-exporter-configuration>
  111. prometheus-node-exporter-configuration
  112. make-prometheus-node-exporter-configuration
  113. prometheus-node-exporter-configuration?
  114. (package prometheus-node-exporter-configuration-package
  115. (default go-github-com-prometheus-node-exporter))
  116. (web-listen-address prometheus-node-exporter-web-listen-address
  117. (default ":9100"))
  118. (textfile-directory prometheus-node-exporter-textfile-directory
  119. (default "/var/lib/prometheus/node-exporter"))
  120. (extra-options prometheus-node-exporter-extra-options
  121. (default '())))
  122. (define %prometheus-node-exporter-accounts
  123. (list (user-account
  124. (name "prometheus-node-exporter")
  125. (group "prometheus-node-exporter")
  126. (system? #t)
  127. (comment "Prometheus node exporter daemon user")
  128. (home-directory "/var/empty")
  129. (shell (file-append shadow "/sbin/nologin")))
  130. (user-group
  131. (name "prometheus-node-exporter")
  132. (system? #t))))
  133. (define prometheus-node-exporter-shepherd-service
  134. (match-lambda
  135. (( $ <prometheus-node-exporter-configuration>
  136. package web-listen-address textfile-directory extra-options)
  137. (list
  138. (shepherd-service
  139. (documentation "Prometheus node exporter.")
  140. (provision '(prometheus-node-exporter))
  141. (requirement '(networking))
  142. (start #~(make-forkexec-constructor
  143. (list #$(file-append package "/bin/node_exporter")
  144. "--web.listen-address" #$web-listen-address
  145. #$@(if textfile-directory
  146. (list "--collector.textfile.directory"
  147. textfile-directory)
  148. '())
  149. #$@extra-options)
  150. #:user "prometheus-node-exporter"
  151. #:group "prometheus-node-exporter"
  152. #:log-file "/var/log/prometheus-node-exporter.log"))
  153. (stop #~(make-kill-destructor)))))))
  154. (define (prometheus-node-exporter-activation config)
  155. (with-imported-modules '((guix build utils))
  156. #~(let ((textfile-directory
  157. #$(prometheus-node-exporter-textfile-directory config)))
  158. (use-modules (guix build utils))
  159. (when textfile-directory
  160. (let ((user (getpw "prometheus-node-exporter")))
  161. #t
  162. (mkdir-p textfile-directory)
  163. (chown textfile-directory (passwd:uid user) (passwd:gid user))
  164. (chmod textfile-directory #o775))))))
  165. (define prometheus-node-exporter-service-type
  166. (service-type
  167. (name 'prometheus-node-exporter)
  168. (description
  169. "Run @command{node_exporter} to serve hardware and OS metrics to
  170. Prometheus.")
  171. (extensions
  172. (list
  173. (service-extension account-service-type
  174. (const %prometheus-node-exporter-accounts))
  175. (service-extension activation-service-type
  176. prometheus-node-exporter-activation)
  177. (service-extension shepherd-root-service-type
  178. prometheus-node-exporter-shepherd-service)))
  179. (default-value (prometheus-node-exporter-configuration))))
  180. ;;;
  181. ;;; Zabbix server
  182. ;;;
  183. (define (uglify-field-name field-name)
  184. (apply string-append
  185. (map (lambda (str)
  186. (if (member (string->symbol str) '(ca db ssl))
  187. (string-upcase str)
  188. (string-capitalize str)))
  189. (string-split (string-delete #\?
  190. (symbol->string field-name))
  191. #\-))))
  192. (define (serialize-field field-name val)
  193. (format #t "~a=~a~%" (uglify-field-name field-name) val))
  194. (define (serialize-number field-name val)
  195. (serialize-field field-name (number->string val)))
  196. (define (serialize-list field-name val)
  197. (if (null? val) "" (serialize-field field-name (string-join val ","))))
  198. (define (serialize-string field-name val)
  199. (if (and (string? val) (string=? val ""))
  200. ""
  201. (serialize-field field-name val)))
  202. (define group? string?)
  203. (define serialize-group
  204. (const ""))
  205. (define include-files? list?)
  206. (define (serialize-include-files field-name val)
  207. (if (null? val) "" (for-each (cut serialize-field 'include <>) val)))
  208. (define extra-options? string?)
  209. (define (serialize-extra-options field-name val)
  210. (if (null? val) "" (display val)))
  211. (define (nginx-server-configuration-list? val)
  212. (and (list? val) (and-map nginx-server-configuration? val)))
  213. (define (serialize-nginx-server-configuration-list field-name val)
  214. "")
  215. (define-configuration zabbix-server-configuration
  216. (zabbix-server
  217. (package zabbix-server)
  218. "The zabbix-server package.")
  219. (user
  220. (string "zabbix")
  221. "User who will run the Zabbix server.")
  222. (group ;for zabbix-server-account procedure
  223. (group "zabbix")
  224. "Group who will run the Zabbix server.")
  225. (db-host
  226. (string "127.0.0.1")
  227. "Database host name.")
  228. (db-name
  229. (string "zabbix")
  230. "Database name.")
  231. (db-user
  232. (string "zabbix")
  233. "Database user.")
  234. (db-password
  235. (string "")
  236. "Database password. Please, use @code{include-files} with
  237. @code{DBPassword=SECRET} inside a specified file instead.")
  238. (db-port
  239. (number 5432)
  240. "Database port.")
  241. (log-type
  242. (string "")
  243. "Specifies where log messages are written to:
  244. @itemize
  245. @item @code{system} - syslog.
  246. @item @code{file} - file specified with @code{log-file} parameter.
  247. @item @code{console} - standard output.
  248. @end itemize\n")
  249. (log-file
  250. (string "/var/log/zabbix/server.log")
  251. "Log file name for @code{log-type} @code{file} parameter.")
  252. (pid-file
  253. (string "/var/run/zabbix/zabbix_server.pid")
  254. "Name of PID file.")
  255. (ssl-ca-location
  256. (string "/etc/ssl/certs/ca-certificates.crt")
  257. "The location of certificate authority (CA) files for SSL server
  258. certificate verification.")
  259. (ssl-cert-location
  260. (string "/etc/ssl/certs")
  261. "Location of SSL client certificates.")
  262. (extra-options
  263. (extra-options "")
  264. "Extra options will be appended to Zabbix server configuration file.")
  265. (include-files
  266. (include-files '())
  267. "You may include individual files or all files in a directory in the
  268. configuration file."))
  269. (define (zabbix-server-account config)
  270. "Return the user accounts and user groups for CONFIG."
  271. (let ((zabbix-user (zabbix-server-configuration-user config))
  272. (zabbix-group (zabbix-server-configuration-group config)))
  273. (list (user-group (name zabbix-group) (system? #t))
  274. (user-account
  275. (name zabbix-user)
  276. (system? #t)
  277. (group zabbix-group)
  278. (comment "zabbix privilege separation user")
  279. (home-directory (string-append "/var/run/" zabbix-user))
  280. (shell (file-append shadow "/sbin/nologin"))))))
  281. (define (zabbix-server-config-file config)
  282. "Return the zabbix-server configuration file corresponding to CONFIG."
  283. (computed-file
  284. "zabbix_server.conf"
  285. #~(begin
  286. (call-with-output-file #$output
  287. (lambda (port)
  288. (display "# Generated by 'zabbix-server-service'.\n" port)
  289. (display #$(with-output-to-string
  290. (lambda ()
  291. (serialize-configuration
  292. config zabbix-server-configuration-fields)))
  293. port)
  294. #t)))))
  295. (define (zabbix-server-activation config)
  296. "Return the activation gexp for CONFIG."
  297. (with-imported-modules '((guix build utils))
  298. #~(begin
  299. (use-modules (guix build utils)
  300. (ice-9 rdelim))
  301. (let ((user (getpw #$(zabbix-server-configuration-user config))))
  302. (for-each (lambda (file)
  303. (let ((directory (dirname file)))
  304. (mkdir-p directory)
  305. (chown directory (passwd:uid user) (passwd:gid user))
  306. (chmod directory #o755)))
  307. (list #$(zabbix-server-configuration-log-file config)
  308. #$(zabbix-server-configuration-pid-file config)
  309. "/etc/zabbix/maintenance.inc.php"))))))
  310. (define (zabbix-server-shepherd-service config)
  311. "Return a <shepherd-service> for Zabbix server with CONFIG."
  312. (list (shepherd-service
  313. (provision '(zabbix-server))
  314. (documentation "Run Zabbix server daemon.")
  315. (start #~(make-forkexec-constructor
  316. (list #$(file-append (zabbix-server-configuration-zabbix-server config)
  317. "/sbin/zabbix_server")
  318. "--config" #$(zabbix-server-config-file config)
  319. "--foreground")
  320. #:user #$(zabbix-server-configuration-user config)
  321. #:group #$(zabbix-server-configuration-group config)
  322. #:pid-file #$(zabbix-server-configuration-pid-file config)
  323. #:environment-variables
  324. (list "SSL_CERT_DIR=/run/current-system/profile\
  325. /etc/ssl/certs"
  326. "SSL_CERT_FILE=/run/current-system/profile\
  327. /etc/ssl/certs/ca-certificates.crt")))
  328. (stop #~(make-kill-destructor)))))
  329. (define zabbix-server-service-type
  330. (service-type
  331. (name 'zabbix-server)
  332. (extensions
  333. (list (service-extension shepherd-root-service-type
  334. zabbix-server-shepherd-service)
  335. (service-extension account-service-type
  336. zabbix-server-account)
  337. (service-extension activation-service-type
  338. zabbix-server-activation)))
  339. (default-value (zabbix-server-configuration))))
  340. (define (generate-zabbix-server-documentation)
  341. (generate-documentation
  342. `((zabbix-server-configuration
  343. ,zabbix-server-configuration-fields))
  344. 'zabbix-server-configuration))
  345. (define-configuration zabbix-agent-configuration
  346. (zabbix-agent
  347. (package zabbix-agentd)
  348. "The zabbix-agent package.")
  349. (user
  350. (string "zabbix")
  351. "User who will run the Zabbix agent.")
  352. (group
  353. (group "zabbix")
  354. "Group who will run the Zabbix agent.")
  355. (hostname
  356. (string "")
  357. "Unique, case sensitive hostname which is required for active checks and
  358. must match hostname as configured on the server.")
  359. (log-type
  360. (string "")
  361. "Specifies where log messages are written to:
  362. @itemize
  363. @item @code{system} - syslog.
  364. @item @code{file} - file specified with @code{log-file} parameter.
  365. @item @code{console} - standard output.
  366. @end itemize\n")
  367. (log-file
  368. (string "/var/log/zabbix/agent.log")
  369. "Log file name for @code{log-type} @code{file} parameter.")
  370. (pid-file
  371. (string "/var/run/zabbix/zabbix_agent.pid")
  372. "Name of PID file.")
  373. (server
  374. (list '("127.0.0.1"))
  375. "List of IP addresses, optionally in CIDR notation, or hostnames of Zabbix
  376. servers and Zabbix proxies. Incoming connections will be accepted only from
  377. the hosts listed here.")
  378. (server-active
  379. (list '("127.0.0.1"))
  380. "List of IP:port (or hostname:port) pairs of Zabbix servers and Zabbix
  381. proxies for active checks. If port is not specified, default port is used.
  382. If this parameter is not specified, active checks are disabled.")
  383. (extra-options
  384. (extra-options "")
  385. "Extra options will be appended to Zabbix server configuration file.")
  386. (include-files
  387. (include-files '())
  388. "You may include individual files or all files in a directory in the
  389. configuration file."))
  390. (define (zabbix-agent-account config)
  391. "Return the user accounts and user groups for CONFIG."
  392. (let ((zabbix-user "zabbix")
  393. (zabbix-group "zabbix"))
  394. (list (user-group (name zabbix-group) (system? #t))
  395. (user-account
  396. (name zabbix-user)
  397. (system? #t)
  398. (group zabbix-group)
  399. (comment "zabbix privilege separation user")
  400. (home-directory (string-append "/var/run/" zabbix-user))
  401. (shell (file-append shadow "/sbin/nologin"))))))
  402. (define (zabbix-agent-activation config)
  403. "Return the activation gexp for CONFIG."
  404. (with-imported-modules '((guix build utils))
  405. #~(begin
  406. (use-modules (guix build utils)
  407. (ice-9 rdelim))
  408. (let ((user
  409. (getpw #$(zabbix-agent-configuration-user config))))
  410. (for-each (lambda (file)
  411. (let ((directory (dirname file)))
  412. (mkdir-p directory)
  413. (chown directory (passwd:uid user) (passwd:gid user))
  414. (chmod directory #o755)))
  415. (list #$(zabbix-agent-configuration-log-file config)
  416. #$(zabbix-agent-configuration-pid-file config)))))))
  417. (define (zabbix-agent-config-file config)
  418. "Return the zabbix-agent configuration file corresponding to CONFIG."
  419. (computed-file
  420. "zabbix_agent.conf"
  421. #~(begin
  422. (call-with-output-file #$output
  423. (lambda (port)
  424. (display "# Generated by 'zabbix-agent-service'.\n" port)
  425. (display #$(with-output-to-string
  426. (lambda ()
  427. (serialize-configuration
  428. config zabbix-agent-configuration-fields)))
  429. port)
  430. #t)))))
  431. (define (zabbix-agent-shepherd-service config)
  432. "Return a <shepherd-service> for Zabbix agent with CONFIG."
  433. (list (shepherd-service
  434. (provision '(zabbix-agent))
  435. (documentation "Run Zabbix agent daemon.")
  436. (start #~(make-forkexec-constructor
  437. (list #$(file-append (zabbix-agent-configuration-zabbix-agent config)
  438. "/sbin/zabbix_agentd")
  439. "--config" #$(zabbix-agent-config-file config)
  440. "--foreground")
  441. #:user #$(zabbix-agent-configuration-user config)
  442. #:group #$(zabbix-agent-configuration-group config)
  443. #:pid-file #$(zabbix-agent-configuration-pid-file config)
  444. #:environment-variables
  445. (list "SSL_CERT_DIR=/run/current-system/profile\
  446. /etc/ssl/certs"
  447. "SSL_CERT_FILE=/run/current-system/profile\
  448. /etc/ssl/certs/ca-certificates.crt")))
  449. (stop #~(make-kill-destructor)))))
  450. (define zabbix-agent-service-type
  451. (service-type
  452. (name 'zabbix-agent)
  453. (extensions
  454. (list (service-extension shepherd-root-service-type
  455. zabbix-agent-shepherd-service)
  456. (service-extension account-service-type
  457. zabbix-agent-account)
  458. (service-extension activation-service-type
  459. zabbix-agent-activation)))
  460. (default-value (zabbix-agent-configuration))))
  461. (define (generate-zabbix-agent-documentation)
  462. (generate-documentation
  463. `((zabbix-agent-configuration
  464. ,zabbix-agent-configuration-fields))
  465. 'zabbix-agent-configuration))
  466. (define %zabbix-front-end-configuration-nginx
  467. (nginx-server-configuration
  468. (root #~(string-append #$zabbix-server:front-end "/share/zabbix/php"))
  469. (index '("index.php"))
  470. (locations
  471. (let ((php-location (nginx-php-location)))
  472. (list (nginx-location-configuration
  473. (inherit php-location)
  474. (body (append (nginx-location-configuration-body php-location)
  475. (list "
  476. fastcgi_param PHP_VALUE \"post_max_size = 16M
  477. max_execution_time = 300\";
  478. ")))))))
  479. (listen '("80"))))
  480. (define-configuration zabbix-front-end-configuration
  481. ;; TODO: Specify zabbix front-end package.
  482. ;; (zabbix-
  483. ;; (package zabbix-front-end)
  484. ;; "The zabbix-front-end package.")
  485. (nginx
  486. (nginx-server-configuration-list
  487. (list %zabbix-front-end-configuration-nginx))
  488. "NGINX configuration.")
  489. (db-host
  490. (string "localhost")
  491. "Database host name.")
  492. (db-port
  493. (number 5432)
  494. "Database port.")
  495. (db-name
  496. (string "zabbix")
  497. "Database name.")
  498. (db-user
  499. (string "zabbix")
  500. "Database user.")
  501. (db-password
  502. (string "")
  503. "Database password. Please, use @code{db-secret-file} instead.")
  504. (db-secret-file
  505. (string "")
  506. "Secret file which will be appended to @file{zabbix.conf.php} file. This
  507. file contains credentials for use by Zabbix front-end. You are expected to
  508. create it manually.")
  509. (zabbix-host
  510. (string "localhost")
  511. "Zabbix server hostname.")
  512. (zabbix-port
  513. (number 10051)
  514. "Zabbix server port."))
  515. (define (zabbix-front-end-config config)
  516. (match-record config <zabbix-front-end-configuration>
  517. (%location db-host db-port db-name db-user db-password db-secret-file
  518. zabbix-host zabbix-port)
  519. (mixed-text-file "zabbix.conf.php"
  520. "\
  521. <?php
  522. // Zabbix GUI configuration file.
  523. global $DB;
  524. $DB['TYPE'] = 'POSTGRESQL';
  525. $DB['SERVER'] = '" db-host "';
  526. $DB['PORT'] = '" (number->string db-port) "';
  527. $DB['DATABASE'] = '" db-name "';
  528. $DB['USER'] = '" db-user "';
  529. $DB['PASSWORD'] = '" (let ((file (location-file %location))
  530. (line (location-line %location))
  531. (column (location-column %location)))
  532. (if (string-null? db-password)
  533. (if (string-null? db-secret-file)
  534. (raise (make-compound-condition
  535. (condition
  536. (&message
  537. (message
  538. (format #f "no '~A' or '~A' field in your '~A' record"
  539. 'db-secret-file 'db-password
  540. 'zabbix-front-end-configuration))))
  541. (condition
  542. (&error-location
  543. (location %location)))))
  544. (string-trim-both
  545. (with-input-from-file db-secret-file
  546. read-string)))
  547. (begin
  548. (display-hint (format #f (G_ "~a:~a:~a: ~a:
  549. Consider using @code{db-secret-file} instead of @code{db-password} for better
  550. security.") file line column 'zabbix-front-end-configuration))
  551. db-password))) "';
  552. // Schema name. Used for IBM DB2 and PostgreSQL.
  553. $DB['SCHEMA'] = '';
  554. $ZBX_SERVER = '" zabbix-host "';
  555. $ZBX_SERVER_PORT = '" (number->string zabbix-port) "';
  556. $ZBX_SERVER_NAME = '';
  557. $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
  558. ")))
  559. (define %maintenance.inc.php
  560. ;; Empty php file to allow us move zabbix-frontend configs to ‘/etc/zabbix’
  561. ;; directory. See ‘install-front-end’ phase in
  562. ;; (@ (gnu packages monitoring) zabbix-server) package.
  563. "\
  564. <?php
  565. ")
  566. (define (zabbix-front-end-activation config)
  567. "Return the activation gexp for CONFIG."
  568. #~(begin
  569. (use-modules (guix build utils))
  570. (mkdir-p "/etc/zabbix")
  571. (call-with-output-file "/etc/zabbix/maintenance.inc.php"
  572. (lambda (port)
  573. (display #$%maintenance.inc.php port)))
  574. (copy-file #$(zabbix-front-end-config config)
  575. "/etc/zabbix/zabbix.conf.php")))
  576. (define zabbix-front-end-service-type
  577. (service-type
  578. (name 'zabbix-front-end)
  579. (extensions
  580. (list (service-extension activation-service-type
  581. zabbix-front-end-activation)
  582. (service-extension nginx-service-type
  583. zabbix-front-end-configuration-nginx)
  584. ;; Make sure php-fpm is instantiated.
  585. (service-extension php-fpm-service-type
  586. (const #t))))
  587. (default-value (zabbix-front-end-configuration))
  588. (description
  589. "Run the zabbix-front-end web interface, which allows users to interact
  590. with Zabbix server.")))
  591. (define (generate-zabbix-front-end-documentation)
  592. (generate-documentation
  593. `((zabbix-front-end-configuration
  594. ,zabbix-front-end-configuration-fields))
  595. 'zabbix-front-end-configuration))