unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#33549] [PATCH 0/6] Add Zabbix services.
@ 2018-11-29 18:47 Oleg Pykhalov
  2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
  2018-12-17 19:22 ` bug#33549: Status: [PATCH 0/6] Add Zabbix services Oleg Pykhalov
  0 siblings, 2 replies; 12+ messages in thread
From: Oleg Pykhalov @ 2018-11-29 18:47 UTC (permalink / raw)
  To: 33549

Hello Guix.

This patch series adds Zabbix server, agent and front-end services.


I replaced ‘match-lambda’ with ‘php-fpm-configuration-*’ procedures in
‘php-fpm-activation’, because it was not obvious for me why build failed after
adding ‘timezone’ field and I spend a plenty of time to figure it out.


I'm not sure about ‘php-with-bcmath’ package.  ‘php’ package has a comment:

    Some of the bundled libraries have no proper upstream.  Ideally we'd
    extract these out as separate packages: "mbstring/libmbfl" "date/lib"
    "bcmath/libbcmath".

Well, ‘php-with-bcmath’ could be replaced in future with ‘bcmath/libbcmath’.
I'm not ready to do this and it will stop a ‘zabbix-front-end’ service from
pushing to master for unknown time.

Thanks,
Oleg.

Oleg Pykhalov (6):
  gnu: zabbix-server: Split output.
  services: monitoring: Add 'zabbix-server'.
  services: monitoring: Add 'zabbix-agent'.
  services: php-fpm: Add 'timezone' configuration.
  gnu: Add php-with-bcmath.
  services: monitoring: Add 'zabbix-front-end'.

 doc/guix.texi               | 320 +++++++++++++++++++++++++
 gnu/packages/monitoring.scm |  21 +-
 gnu/packages/php.scm        |  10 +
 gnu/services/monitoring.scm | 460 +++++++++++++++++++++++++++++++++++-
 gnu/services/web.scm        |  48 ++--
 gnu/tests/monitoring.scm    | 233 +++++++++++++++++-
 6 files changed, 1066 insertions(+), 26 deletions(-)

-- 
2.19.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output.
  2018-11-29 18:47 [bug#33549] [PATCH 0/6] Add Zabbix services Oleg Pykhalov
@ 2018-11-29 18:50 ` Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 2/6] services: monitoring: Add 'zabbix-server' Oleg Pykhalov
                     ` (4 more replies)
  2018-12-17 19:22 ` bug#33549: Status: [PATCH 0/6] Add Zabbix services Oleg Pykhalov
  1 sibling, 5 replies; 12+ messages in thread
From: Oleg Pykhalov @ 2018-11-29 18:50 UTC (permalink / raw)
  To: 33549

* gnu/packages/monitoring.scm (zabbix-server)[outputs]: Add 'front-end' and
'schema' outputs.
---
 gnu/packages/monitoring.scm | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/monitoring.scm b/gnu/packages/monitoring.scm
index b69ec07158..35fe4c7690 100644
--- a/gnu/packages/monitoring.scm
+++ b/gnu/packages/monitoring.scm
@@ -182,21 +182,34 @@ solution (client-side agent)")
   (package
     (inherit zabbix-agentd)
     (name "zabbix-server")
+    (outputs '("out" "front-end" "schema"))
     (arguments
      (substitute-keyword-arguments
          `(#:phases
            (modify-phases %standard-phases
-             (add-after 'install 'install-frontend
+             (add-after 'install 'install-front-end
                (lambda* (#:key outputs #:allow-other-keys)
-                 (let* ((php (string-append (assoc-ref outputs "out")
+                 (let* ((php (string-append (assoc-ref outputs "front-end")
                                             "/share/zabbix/php"))
                         (front-end-conf (string-append php "/conf"))
                         (etc (string-append php "/etc")))
                    (mkdir-p php)
-                   (copy-recursively "./frontends/php" php)
+                   (copy-recursively "frontends/php" php)
+                   ;; Make front-end write config to ‘/etc/zabbix’ directory.
                    (rename-file front-end-conf
                                 (string-append front-end-conf "-example"))
-                   (symlink "/etc/zabbix" front-end-conf)))))
+                   (symlink "/etc/zabbix" front-end-conf))
+                 #t))
+             (add-after 'install 'install-schema
+               (lambda* (#:key outputs #:allow-other-keys)
+                 (let ((database-directory
+                        (string-append (assoc-ref outputs "schema")
+                                       "/database")))
+                   (for-each delete-file
+                             (find-files "database" "Makefile\\.in|\\.am$"))
+                   (mkdir-p database-directory)
+                   (copy-recursively "database" database-directory))
+                 #t)))
            ,@(package-arguments zabbix-agentd))
        ((#:configure-flags flags)
         `(cons* "--enable-server"
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 2/6] services: monitoring: Add 'zabbix-server'.
  2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
@ 2018-11-29 18:50   ` Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 3/6] services: monitoring: Add 'zabbix-agent' Oleg Pykhalov
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Oleg Pykhalov @ 2018-11-29 18:50 UTC (permalink / raw)
  To: 33549

* gnu/services/monitoring.scm (uglify-field-name, serialize-field,
serialize-number, serialize-list, serialize-string, serialize-include-files,
zabbix-server-account, zabbix-server-config-file, zabbix-server-activation,
zabbix-server-shepherd-service, generate-zabbix-server-documentation): New
procedures.
(zabbix-server-service-type): New variable.
* gnu/tests/monitoring.scm (%psql-user-create-zabbix,
%psql-db-zabbix-create-script, %psql-db-create-zabbix, %psql-db-import-zabbix,
%zabbix-os, %test-zabbix): New variables.
(run-zabbix-server-test): New procedure.
* doc/guix.texi (Monitoring Services): Document 'zabbix-server'.
---
 doc/guix.texi               | 140 +++++++++++++++++++++++++++
 gnu/services/monitoring.scm | 185 +++++++++++++++++++++++++++++++++++-
 gnu/tests/monitoring.scm    | 168 +++++++++++++++++++++++++++++++-
 3 files changed, 491 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index c040a8531a..48f7798742 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -16613,6 +16613,146 @@ Bind the web interface to the specified address.
 @end table
 @end deftp
 
+@subsubheading Zabbix server
+@cindex zabbix zabbix-server
+Zabbix provides monitoring metrics, among others network utilization, CPU load
+and disk space consumption:
+
+@itemize
+@item High performance, high capacity (able to monitor hundreds of thousands of devices).
+@item Auto-discovery of servers and network devices and interfaces.
+@item Low-level discovery, allows to automatically start monitoring new items, file systems or network interfaces among others.
+@item Distributed monitoring with centralized web administration.
+@item Native high performance agents.
+@item SLA, and ITIL KPI metrics on reporting.
+@item High-level (business) view of monitored resources through user-defined visual console screens and dashboards.
+@item Remote command execution through Zabbix proxies.
+@end itemize
+
+@c %start of fragment
+
+Available @code{zabbix-server-configuration} fields are:
+
+@deftypevr {@code{zabbix-server-configuration} parameter} package zabbix-server
+The zabbix-server package.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string user
+User who will run the Zabbix server.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} group group
+Group who will run the Zabbix server.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string db-host
+Database host name.
+
+Defaults to @samp{"127.0.0.1"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string db-name
+Database name.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string db-user
+Database user.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string db-password
+Database password.  Please, use @code{include-files} instead.
+
+Defaults to @samp{""}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} number db-port
+Database port.
+
+Defaults to @samp{5432}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string log-type
+Specifies where log messages are written to:
+
+@itemize @bullet
+@item
+@code{system} - syslog.
+
+@item
+@code{file} - file specified with @code{log-file} parameter.
+
+@item
+@code{console} - standard output.
+
+@end itemize
+
+Defaults to @samp{""}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string log-file
+Log file name for @code{log-type} @code{file} parameter.
+
+Defaults to @samp{"/var/log/zabbix/server.log"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string pid-file
+Name of PID file.
+
+Defaults to @samp{"/var/run/zabbix/zabbix_server.pid"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string ssl-ca-location
+The location of certificate authority (CA) files for SSL server
+certificate verification.
+
+Defaults to @samp{"/etc/ssl/certs/ca-certificates.crt"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string ssl-cert-location
+Location of SSL client certificates.
+
+Defaults to @samp{"/etc/ssl/certs"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} string extra-options
+Extra options will be appended to Zabbix server configuration file.
+
+Defaults to @samp{""}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-server-configuration} parameter} include-files include-files
+You may include individual files or all files in a directory in the
+configuration file.
+
+Defaults to @samp{()}.
+
+@end deftypevr
+
+
+@c %end of fragment
+
 @node Kerberos Services
 @subsubsection Kerberos Services
 @cindex Kerberos
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index aa3b63a0e4..9655fb95e9 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.org>
 ;;; Copyright © 2018 Gábor Boskovits <boskovits@gmail.com>
+;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -19,17 +20,23 @@
 
 (define-module (gnu services monitoring)
   #:use-module (gnu services)
+  #:use-module (gnu services configuration)
   #:use-module (gnu services shepherd)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages monitoring)
   #:use-module (gnu system shadow)
   #:use-module (guix gexp)
+  #:use-module (guix packages)
   #:use-module (guix records)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-26)
   #:export (darkstat-configuration
             prometheus-node-exporter-configuration
             darkstat-service-type
-            prometheus-node-exporter-service-type))
+            prometheus-node-exporter-service-type
+
+            zabbix-server-configuration
+            zabbix-server-service-type))
 
 \f
 ;;;
@@ -125,3 +132,179 @@ prometheus.")
     (list (service-extension
            shepherd-root-service-type
            (compose list prometheus-node-exporter-shepherd-service))))))
+
+\f
+;;;
+;;; Zabbix server
+;;;
+
+(define (uglify-field-name field-name)
+  (apply string-append
+         (map (lambda (str)
+                (if (member (string->symbol str) '(ca db ssl))
+                    (string-upcase str)
+                    (string-capitalize str)))
+              (string-split (string-delete #\?
+                                           (symbol->string field-name))
+                            #\-))))
+
+(define (serialize-field field-name val)
+  (format #t "~a=~a~%" (uglify-field-name field-name) val))
+
+(define (serialize-number field-name val)
+  (serialize-field field-name (number->string val)))
+
+(define (serialize-list field-name val)
+  (if (null? val) "" (serialize-field field-name (string-join val ","))))
+
+(define (serialize-string field-name val)
+  (if (and (string? val) (string=? val ""))
+      ""
+      (serialize-field field-name val)))
+
+(define group? string?)
+
+(define serialize-group
+  (const ""))
+
+(define include-files? list?)
+
+(define (serialize-include-files field-name val)
+  (if (null? val) "" (for-each (cut serialize-field 'include <>) val)))
+
+(define-configuration zabbix-server-configuration
+  (zabbix-server
+   (package zabbix-server)
+   "The zabbix-server package.")
+  (user
+   (string "zabbix")
+   "User who will run the Zabbix server.")
+  (group ;for zabbix-server-account procedure
+   (group "zabbix")
+   "Group who will run the Zabbix server.")
+  (db-host
+   (string "127.0.0.1")
+   "Database host name.")
+  (db-name
+   (string "zabbix")
+   "Database name.")
+  (db-user
+   (string "zabbix")
+   "Database user.")
+  (db-password
+   (string "")
+   "Database password.  Please, use @code{include-files} instead.")
+  (db-port
+   (number 5432)
+   "Database port.")
+  (log-type
+   (string "")
+   "Specifies where log messages are written to:
+@itemize
+@item @code{system} - syslog.
+@item @code{file} - file specified with @code{log-file} parameter.
+@item @code{console} - standard output.
+@end itemize\n")
+  (log-file
+   (string "/var/log/zabbix/server.log")
+   "Log file name for @code{log-type} @code{file} parameter.")
+  (pid-file
+   (string  "/var/run/zabbix/zabbix_server.pid")
+   "Name of PID file.")
+  (ssl-ca-location
+   (string "/etc/ssl/certs/ca-certificates.crt")
+   "The location of certificate authority (CA) files for SSL server
+certificate verification.")
+  (ssl-cert-location
+   (string "/etc/ssl/certs")
+   "Location of SSL client certificates.")
+  (extra-options
+   (string "")
+   "Extra options will be appended to Zabbix server configuration file.")
+  (include-files
+   (include-files '())
+   "You may include individual files or all files in a directory in the
+configuration file."))
+
+(define (zabbix-server-account config)
+  "Return the user accounts and user groups for CONFIG."
+  (let ((zabbix-user (zabbix-server-configuration-user config))
+        (zabbix-group (zabbix-server-configuration-group config)))
+    (list (user-group (name zabbix-group) (system? #t))
+          (user-account
+           (name zabbix-user)
+           (system? #t)
+           (group zabbix-group)
+           (comment "zabbix privilege separation user")
+           (home-directory (string-append "/var/run/" zabbix-user))
+           (shell #~(string-append #$shadow "/sbin/nologin"))))))
+
+(define (zabbix-server-config-file config)
+  "Return the zabbix-server configuration file corresponding to CONFIG."
+  (computed-file
+   "zabbix_server.conf"
+   #~(begin
+       (call-with-output-file #$output
+         (lambda (port)
+           (display "# Generated by 'zabbix-server-service'.\n" port)
+           (display #$(with-output-to-string
+                        (lambda ()
+                          (serialize-configuration
+                           config zabbix-server-configuration-fields)))
+                    port)
+           #t)))))
+
+(define (zabbix-server-activation config)
+  "Return the activation gexp for CONFIG."
+  (with-imported-modules '((guix build utils)
+                           (ice-9 rdelim))
+    #~(begin
+        (use-modules (guix build utils)
+                     (ice-9 rdelim))
+        (let ((user (getpw #$(zabbix-server-configuration-user config))))
+          (for-each (lambda (file)
+                      (let ((directory (dirname file)))
+                        (mkdir-p directory)
+                        (chown directory (passwd:uid user) (passwd:gid user))
+                        (chmod directory #o755)))
+                    (list #$(zabbix-server-configuration-log-file config)
+                          #$(zabbix-server-configuration-pid-file config)
+                          "/etc/zabbix/maintenance.inc.php"))))))
+
+(define (zabbix-server-shepherd-service config)
+  "Return a <shepherd-service> for Zabbix server with CONFIG."
+  (list (shepherd-service
+         (provision '(zabbix-server))
+         (documentation "Run Zabbix server daemon.")
+         (start #~(make-forkexec-constructor
+                   (list #$(file-append (zabbix-server-configuration-zabbix-server config)
+                                        "/sbin/zabbix_server")
+                         "--config" #$(zabbix-server-config-file config)
+                         "--foreground")
+                   #:user #$(zabbix-server-configuration-user config)
+                   #:group #$(zabbix-server-configuration-group config)
+                   #:pid-file #$(zabbix-server-configuration-pid-file config)
+                   #:environment-variables
+                   (list "SSL_CERT_DIR=/run/current-system/profile\
+/etc/ssl/certs"
+                         "SSL_CERT_FILE=/run/current-system/profile\
+/etc/ssl/certs/ca-certificates.crt")))
+         (stop #~(make-kill-destructor)))))
+
+(define zabbix-server-service-type
+  (service-type
+   (name 'zabbix-server)
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             zabbix-server-shepherd-service)
+          (service-extension account-service-type
+                             zabbix-server-account)
+          (service-extension activation-service-type
+                             zabbix-server-activation)))
+   (default-value (zabbix-server-configuration))))
+
+(define (generate-zabbix-server-documentation)
+  (generate-documentation
+   `((zabbix-server-configuration
+      ,zabbix-server-configuration-fields))
+   'zabbix-server-configuration))
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index 3320a19a77..7a704eb01d 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2018 Gábor Boskovits  <boskovits@gmail.com>
+;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -17,13 +18,20 @@
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (gnu tests monitoring)
+  #:use-module (gnu packages databases)
+  #:use-module (gnu packages monitoring)
   #:use-module (gnu services)
   #:use-module (gnu services monitoring)
   #:use-module (gnu services networking)
+  #:use-module (gnu services databases)
+  #:use-module (gnu services shepherd)
   #:use-module (gnu system vm)
+  #:use-module (gnu system)
   #:use-module (gnu tests)
   #:use-module (guix gexp)
-  #:export (%test-prometheus-node-exporter))
+  #:use-module (guix modules)
+  #:export (%test-prometheus-node-exporter
+            %test-zabbix))
 
 \f
 ;;;
@@ -95,3 +103,161 @@
    (description "Connect to a running prometheus-node-exporter server.")
    (value (run-prometheus-node-exporter-server-test
            name %prometheus-node-exporter-os))))
+
+\f
+;;;
+;;; Zabbix
+;;;
+
+(define %psql-user-create-zabbix
+  "\
+sudo -u postgres psql <<< \"create user zabbix password 'zabbix';\"
+")
+
+(define %psql-db-zabbix-create-script
+  "\
+sudo -u postgres psql --no-align <<< \\\\du
+")
+
+(define %psql-db-create-zabbix
+  "\
+sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix
+")
+
+(define %psql-db-import-zabbix
+  #~(format #f "\
+cat ~a | sudo -u zabbix psql zabbix;
+cat ~a | sudo -u zabbix psql zabbix;
+cat ~a | sudo -u zabbix psql zabbix;
+"
+            (string-append #$zabbix-server:schema
+                           "/database/postgresql/schema.sql")
+            (string-append #$zabbix-server:schema
+                           "/database/postgresql/images.sql")
+            (string-append #$zabbix-server:schema
+                           "/database/postgresql/data.sql")))
+
+(define* (run-zabbix-server-test name test-os)
+  "Run tests in %ZABBIX-OS, which has zabbix running."
+  (define os
+    (marionette-operating-system
+     test-os
+     #:imported-modules '((gnu services herd))))
+
+  (define vm
+    (virtual-machine
+     (operating-system os)
+     (port-forwardings '((8080 . 80)))
+     (memory-size 1024)))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (srfi srfi-11)
+                       (srfi srfi-64)
+                       (gnu build marionette)
+                       (web client)
+                       (web response)
+                       (ice-9 popen)
+                       (ice-9 rdelim))
+
+          (define marionette
+            (make-marionette (list #$vm)))
+
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin #$name)
+
+          ;; XXX: Shepherd reads the config file *before* binding its control
+          ;; socket, so /var/run/shepherd/socket might not exist yet when the
+          ;; 'marionette' service is started.
+          (test-assert "shepherd socket ready"
+            (marionette-eval
+             `(begin
+                (use-modules (gnu services herd))
+                (let loop ((i 10))
+                  (cond ((file-exists? (%shepherd-socket-file))
+                         #t)
+                        ((> i 0)
+                         (sleep 1)
+                         (loop (- i 1)))
+                        (else
+                         'failure))))
+             marionette))
+
+          (test-assert "postgres service running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (start-service 'postgres))
+             marionette))
+
+          (test-eq "postgres create zabbix user"
+            0
+            (marionette-eval '(begin (system #$%psql-user-create-zabbix))
+                             marionette))
+
+          (test-equal "postgres find zabbix user"
+            "List of roles
+Role name|Attributes|Member of
+postgres|Superuser, Create role, Create DB, Replication, Bypass RLS|{}
+zabbix||{}
+"
+            (marionette-eval
+             '(begin (let* ((port (open-pipe #$%psql-db-zabbix-create-script
+                                             OPEN_READ))
+                            (output (read-string port))
+                            (status (close-pipe port)))
+                       output))
+             marionette))
+
+          (test-eq "postgres create zabbix db"
+            0
+            (marionette-eval '(begin (system #$%psql-db-create-zabbix))
+                             marionette))
+
+          (test-eq "postgres import zabbix db"
+            0
+            (marionette-eval '(begin (system #$%psql-db-import-zabbix))
+                             marionette))
+
+          ;; Wait for zabbix-server to be up and running.
+          (test-assert "zabbix-server running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (start-service 'zabbix-server))
+             marionette))
+
+          ;; Make sure the PID file is created.
+          (test-assert "zabbix-server PID file"
+            (marionette-eval
+             '(file-exists? "/var/run/zabbix/zabbix_server.pid")
+             marionette))
+
+          (test-end)
+
+          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+  (gexp->derivation (string-append name "-test") test))
+
+(define %zabbix-os
+  ;; Return operating system under test.
+  (let ((base-os
+         (simple-operating-system
+          (service dhcp-client-service-type)
+          (postgresql-service)
+          (service zabbix-server-service-type
+                   (zabbix-server-configuration
+                    (db-password "zabbix")
+                    (log-type "console"))))))
+    (operating-system
+      (inherit base-os)
+      (packages (cons* postgresql (operating-system-packages base-os))))))
+
+(define %test-zabbix
+  (system-test
+   (name "zabbix")
+   (description "Connect to a running Zabbix")
+   (value (run-zabbix-server-test name %zabbix-os))))
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 3/6] services: monitoring: Add 'zabbix-agent'.
  2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 2/6] services: monitoring: Add 'zabbix-server' Oleg Pykhalov
@ 2018-11-29 18:50   ` Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 4/6] services: php-fpm: Add 'timezone' configuration Oleg Pykhalov
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Oleg Pykhalov @ 2018-11-29 18:50 UTC (permalink / raw)
  To: 33549

* doc/guix.texi (Monitoring Services): Document 'zabbix-agent'.
* gnu/services/monitoring.scm (zabbix-server-service-type,
zabbix-agent-account, zabbix-agent-activation, zabbix-agent-config-file,
zabbix-agent-shepherd-service, generate-zabbix-agent-documentation): New
procedures.
(zabbix-agent-service-type): New variable.
* gnu/tests/monitoring.scm (run-zabbix-server-test): Test 'zabbix-agent'.
(%zabbix-os): Add 'zabbix-agent' service.
---
 doc/guix.texi               | 103 ++++++++++++++++++++++++++++
 gnu/services/monitoring.scm | 133 +++++++++++++++++++++++++++++++++++-
 gnu/tests/monitoring.scm    |  18 ++++-
 3 files changed, 252 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 48f7798742..7b8f7acd29 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -16750,6 +16750,109 @@ Defaults to @samp{()}.
 
 @end deftypevr
 
+@c %end of fragment
+
+@subsubheading Zabbix agent
+@cindex zabbix zabbix-agent
+
+Zabbix agent gathers information for Zabbix server.
+
+@c %start of fragment
+
+Available @code{zabbix-agent-configuration} fields are:
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} package zabbix-agent
+The zabbix-agent package.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} string user
+User who will run the Zabbix agent.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} group group
+Group who will run the Zabbix agent.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} string hostname
+Unique, case sensitive hostname which is required for active checks and
+must match hostname as configured on the server.
+
+Defaults to @samp{"Zabbix server"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} string log-type
+Specifies where log messages are written to:
+
+@itemize @bullet
+@item
+@code{system} - syslog.
+
+@item
+@code{file} - file specified with @code{log-file} parameter.
+
+@item
+@code{console} - standard output.
+
+@end itemize
+
+Defaults to @samp{""}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} string log-file
+Log file name for @code{log-type} @code{file} parameter.
+
+Defaults to @samp{"/var/log/zabbix/agent.log"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} string pid-file
+Name of PID file.
+
+Defaults to @samp{"/var/run/zabbix/zabbix_agent.pid"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} list server
+List of IP addresses, optionally in CIDR notation, or hostnames of
+Zabbix servers and Zabbix proxies.  Incoming connections will be
+accepted only from the hosts listed here.
+
+Defaults to @samp{("127.0.0.1")}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} list server-active
+List of IP:port (or hostname:port) pairs of Zabbix servers and Zabbix
+proxies for active checks.  If port is not specified, default port is
+used.  If this parameter is not specified, active checks are disabled.
+
+Defaults to @samp{("127.0.0.1")}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} string extra-options
+Extra options will be appended to Zabbix server configuration file.
+
+Defaults to @samp{""}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-agent-configuration} parameter} include-files include-files
+You may include individual files or all files in a directory in the
+configuration file.
+
+Defaults to @samp{()}.
+
+@end deftypevr
 
 @c %end of fragment
 
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index 9655fb95e9..274228af89 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -36,7 +36,9 @@
             prometheus-node-exporter-service-type
 
             zabbix-server-configuration
-            zabbix-server-service-type))
+            zabbix-server-service-type
+            zabbix-agent-configuration
+            zabbix-agent-service-type))
 
 \f
 ;;;
@@ -308,3 +310,132 @@ configuration file."))
    `((zabbix-server-configuration
       ,zabbix-server-configuration-fields))
    'zabbix-server-configuration))
+
+(define-configuration zabbix-agent-configuration
+  (zabbix-agent
+   (package zabbix-agentd)
+   "The zabbix-agent package.")
+  (user
+   (string "zabbix")
+   "User who will run the Zabbix agent.")
+  (group
+   (group "zabbix")
+   "Group who will run the Zabbix agent.")
+  (hostname
+   (string "Zabbix server")
+   "Unique, case sensitive hostname which is required for active checks and
+must match hostname as configured on the server.")
+  (log-type
+   (string "")
+   "Specifies where log messages are written to:
+@itemize
+@item @code{system} - syslog.
+@item @code{file} - file specified with @code{log-file} parameter.
+@item @code{console} - standard output.
+@end itemize\n")
+  (log-file
+   (string "/var/log/zabbix/agent.log")
+   "Log file name for @code{log-type} @code{file} parameter.")
+  (pid-file
+   (string "/var/run/zabbix/zabbix_agent.pid")
+   "Name of PID file.")
+  (server
+   (list '("127.0.0.1"))
+   "List of IP addresses, optionally in CIDR notation, or hostnames of Zabbix
+servers and Zabbix proxies.  Incoming connections will be accepted only from
+the hosts listed here.")
+  (server-active
+   (list '("127.0.0.1"))
+   "List of IP:port (or hostname:port) pairs of Zabbix servers and Zabbix
+proxies for active checks.  If port is not specified, default port is used.
+If this parameter is not specified, active checks are disabled.")
+  (extra-options
+   (string "")
+   "Extra options will be appended to Zabbix server configuration file.")
+  (include-files
+   (include-files '())
+   "You may include individual files or all files in a directory in the
+configuration file."))
+
+(define (zabbix-agent-account config)
+  "Return the user accounts and user groups for CONFIG."
+  (let ((zabbix-user "zabbix")
+        (zabbix-group "zabbix"))
+    (list (user-group (name zabbix-group) (system? #t))
+          (user-account
+           (name zabbix-user)
+           (system? #t)
+           (group zabbix-group)
+           (comment "zabbix privilege separation user")
+           (home-directory (string-append "/var/run/" zabbix-user))
+           (shell #~(string-append #$shadow "/sbin/nologin"))))))
+
+(define (zabbix-agent-activation config)
+  "Return the activation gexp for CONFIG."
+  (with-imported-modules '((guix build utils)
+                           (ice-9 rdelim))
+    #~(begin
+        (use-modules (guix build utils)
+                     (ice-9 rdelim))
+        (let ((user
+               (getpw #$(zabbix-agent-configuration-user config))))
+          (for-each (lambda (file)
+                      (let ((directory (dirname file)))
+                        (mkdir-p directory)
+                        (chown directory (passwd:uid user) (passwd:gid user))
+                        (chmod directory #o755)))
+                    (list #$(zabbix-agent-configuration-log-file config)
+                          #$(zabbix-agent-configuration-pid-file config)))))))
+
+(define (zabbix-agent-config-file config)
+  "Return the zabbix-agent configuration file corresponding to CONFIG."
+  (computed-file
+   "zabbix_agent.conf"
+   #~(begin
+       (call-with-output-file #$output
+         (lambda (port)
+           (display "# Generated by 'zabbix-agent-service'.\n" port)
+           (display #$(with-output-to-string
+                        (lambda ()
+                          (serialize-configuration
+                           config zabbix-agent-configuration-fields)))
+                    port)
+           #t)))))
+
+(define (zabbix-agent-shepherd-service config)
+  "Return a <shepherd-service> for Zabbix agent with CONFIG."
+  (list (shepherd-service
+         (provision '(zabbix-agent))
+         (documentation "Run Zabbix agent daemon.")
+         (start #~(make-forkexec-constructor
+                   (list #$(file-append (zabbix-agent-configuration-zabbix-agent config)
+                                        "/sbin/zabbix_agentd")
+                         "--config" #$(zabbix-agent-config-file config)
+                         "--foreground")
+                   #:user #$(zabbix-agent-configuration-user config)
+                   #:group #$(zabbix-agent-configuration-group config)
+                   #:pid-file #$(zabbix-agent-configuration-pid-file config)
+                   #:environment-variables
+                   (list "SSL_CERT_DIR=/run/current-system/profile\
+/etc/ssl/certs"
+                         "SSL_CERT_FILE=/run/current-system/profile\
+/etc/ssl/certs/ca-certificates.crt")))
+         (stop #~(make-kill-destructor)))))
+
+(define zabbix-agent-service-type
+  (service-type
+   (name 'zabbix-agent)
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             zabbix-agent-shepherd-service)
+          (service-extension account-service-type
+                             zabbix-agent-account)
+          (service-extension activation-service-type
+                             zabbix-agent-activation)))
+   (default-value (zabbix-agent-configuration))))
+
+(define (generate-zabbix-agent-documentation)
+  (generate-documentation
+   `((zabbix-agent-configuration
+      ,zabbix-agent-configuration-fields))
+   'zabbix-agent-configuration))
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index 7a704eb01d..ec9e086ff4 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
@@ -236,6 +236,20 @@ zabbix||{}
              '(file-exists? "/var/run/zabbix/zabbix_server.pid")
              marionette))
 
+          ;; Wait for zabbix-agent to be up and running.
+          (test-assert "zabbix-agent running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (start-service 'zabbix-agent))
+             marionette))
+
+          ;; Make sure the PID file is created.
+          (test-assert "zabbix-agent PID file"
+            (marionette-eval
+             '(file-exists? "/var/run/zabbix/zabbix_agent.pid")
+             marionette))
+
           (test-end)
 
           (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
@@ -251,7 +265,9 @@ zabbix||{}
           (service zabbix-server-service-type
                    (zabbix-server-configuration
                     (db-password "zabbix")
-                    (log-type "console"))))))
+                    (log-type "console")))
+
+          (service zabbix-agent-service-type))))
     (operating-system
       (inherit base-os)
       (packages (cons* postgresql (operating-system-packages base-os))))))
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 4/6] services: php-fpm: Add 'timezone' configuration.
  2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 2/6] services: monitoring: Add 'zabbix-server' Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 3/6] services: monitoring: Add 'zabbix-agent' Oleg Pykhalov
@ 2018-11-29 18:50   ` Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 5/6] gnu: Add php-with-bcmath Oleg Pykhalov
  2018-11-29 18:50   ` [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end' Oleg Pykhalov
  4 siblings, 0 replies; 12+ messages in thread
From: Oleg Pykhalov @ 2018-11-29 18:50 UTC (permalink / raw)
  To: 33549

* gnu/services/web.scm: (<php-fpm-configuration>)[timezone]: New record field.
(default-php-fpm-config, php-fpm-shepherd-service, php-fpm-activation): Use
this.
* doc/guix.texi (Web Services): Document this.
---
 doc/guix.texi        |  2 ++
 gnu/services/web.scm | 48 ++++++++++++++++++++++++++------------------
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 7b8f7acd29..d83071b432 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -17608,6 +17608,8 @@ Determines whether php errors and warning should be sent to clients
 and displayed in their browsers.
 This is useful for local php development, but a security risk for public sites,
 as error messages can reveal passwords and personal data.
+@item @code{timezone} (default @code{#f})
+Specifies @code{php_admin_value[date.timezone]} parameter.
 @item @code{workers-logfile} (default @code{(string-append "/var/log/php" (version-major (package-version php)) "-fpm.www.log")})
 This file will log the @code{stderr} outputs of php worker processes.
 Can be set to @code{#f} to disable logging.
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index fcf453c248..d71fed20ed 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -142,6 +142,7 @@
             php-fpm-configuration-log-file
             php-fpm-configuration-process-manager
             php-fpm-configuration-display-errors
+            php-fpm-configuration-timezone
             php-fpm-configuration-workers-log-file
             php-fpm-configuration-file
 
@@ -773,6 +774,8 @@ of index files."
                     (default (php-fpm-dynamic-process-manager-configuration)))
   (display-errors   php-fpm-configuration-display-errors
                     (default #f))
+  (timezone         php-fpm-configuration-timezone
+                    (default #f))
   (workers-log-file php-fpm-configuration-workers-log-file
                     (default (string-append "/var/log/php"
                                             (version-major (package-version php))
@@ -827,7 +830,7 @@ of index files."
        (shell (file-append shadow "/sbin/nologin")))))))
 
 (define (default-php-fpm-config socket user group socket-user socket-group
-          pid-file log-file pm display-errors workers-log-file)
+          pid-file log-file pm display-errors timezone workers-log-file)
   (apply mixed-text-file "php-fpm.conf"
          (flatten
           "[global]\n"
@@ -840,6 +843,10 @@ of index files."
           "listen.owner =" socket-user "\n"
           "listen.group =" socket-group "\n"
 
+          (if timezone
+              (string-append "php_admin_value[date.timezone] = \"" timezone "\"\n")
+              "")
+
           (match pm
             (($ <php-fpm-dynamic-process-manager-configuration>
                 pm.max-children
@@ -879,7 +886,8 @@ of index files."
 (define php-fpm-shepherd-service
   (match-lambda
     (($ <php-fpm-configuration> php socket user group socket-user socket-group
-                                pid-file log-file pm display-errors workers-log-file file)
+                                pid-file log-file pm display-errors
+                                timezone workers-log-file file)
      (list (shepherd-service
             (provision '(php-fpm))
             (documentation "Run the php-fpm daemon.")
@@ -890,27 +898,27 @@ of index files."
                         #$(or file
                               (default-php-fpm-config socket user group
                                 socket-user socket-group pid-file log-file
-                                pm display-errors workers-log-file)))
+                                pm display-errors timezone workers-log-file)))
                       #:pid-file #$pid-file))
             (stop #~(make-kill-destructor)))))))
 
-(define php-fpm-activation
-  (match-lambda
-    (($ <php-fpm-configuration> _ _ user _ _ _ _ log-file _ _ workers-log-file _)
-     #~(begin
-         (use-modules (guix build utils))
-         (let* ((user (getpwnam #$user))
-                (touch (lambda (file-name)
-                         (call-with-output-file file-name (const #t))))
-                (init-log-file
-                 (lambda (file-name)
-                   (when #$workers-log-file
-                     (when (not (file-exists? file-name))
-                       (touch file-name))
-                     (chown file-name (passwd:uid user) (passwd:gid user))
-                     (chmod file-name #o660)))))
-           (init-log-file #$log-file)
-           (init-log-file #$workers-log-file))))))
+(define (php-fpm-activation config)
+  #~(begin
+      (use-modules (guix build utils))
+      (let* ((user (getpwnam #$(php-fpm-configuration-user config)))
+             (touch (lambda (file-name)
+                      (call-with-output-file file-name (const #t))))
+             (workers-log-file
+              #$(php-fpm-configuration-workers-log-file config))
+             (init-log-file
+              (lambda (file-name)
+                (when workers-log-file
+                  (when (not (file-exists? file-name))
+                    (touch file-name))
+                  (chown file-name (passwd:uid user) (passwd:gid user))
+                  (chmod file-name #o660)))))
+        (init-log-file #$(php-fpm-configuration-log-file config))
+        (init-log-file workers-log-file))))
 
 
 (define php-fpm-service-type
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 5/6] gnu: Add php-with-bcmath.
  2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
                     ` (2 preceding siblings ...)
  2018-11-29 18:50   ` [bug#33549] [PATCH 4/6] services: php-fpm: Add 'timezone' configuration Oleg Pykhalov
@ 2018-11-29 18:50   ` Oleg Pykhalov
  2018-12-19 15:20     ` Ludovic Courtès
  2018-11-29 18:50   ` [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end' Oleg Pykhalov
  4 siblings, 1 reply; 12+ messages in thread
From: Oleg Pykhalov @ 2018-11-29 18:50 UTC (permalink / raw)
  To: 33549

* gnu/packages/php.scm (php-with-bcmath): New variable.
---
 gnu/packages/php.scm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gnu/packages/php.scm b/gnu/packages/php.scm
index a22591d377..07246b0833 100644
--- a/gnu/packages/php.scm
+++ b/gnu/packages/php.scm
@@ -48,6 +48,7 @@
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix build-system gnu)
+  #:use-module (guix utils)
   #:use-module ((guix licenses) #:prefix license:))
 
 (define gd-for-php
@@ -360,3 +361,12 @@ systems, web content management systems and web frameworks." )
               license:lgpl2.1+                              ; ext/bcmath/libbcmath
               license:bsd-2                                 ; ext/fileinfo/libmagic
               license:expat))))                             ; ext/date/lib
+
+(define-public php-with-bcmath
+  (package
+    (inherit php)
+    (name "php-with-bcmath")
+    (arguments
+     (substitute-keyword-arguments (package-arguments php)
+       ((#:configure-flags flags)
+        `(cons "--enable-bcmath" ,flags))))))
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end'.
  2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
                     ` (3 preceding siblings ...)
  2018-11-29 18:50   ` [bug#33549] [PATCH 5/6] gnu: Add php-with-bcmath Oleg Pykhalov
@ 2018-11-29 18:50   ` Oleg Pykhalov
  2018-12-19 15:27     ` Ludovic Courtès
  4 siblings, 1 reply; 12+ messages in thread
From: Oleg Pykhalov @ 2018-11-29 18:50 UTC (permalink / raw)
  To: 33549

* gnu/services/monitoring.scm (nginx-server-configuration-list?,
serialize-nginx-server-configuration-list, zabbix-front-end-configuration,
zabbix-front-end-config, zabbix-front-end-activation,
generate-zabbix-front-end-documentation): New procedures.
(%zabbix-front-end-configuration-nginx, %maintenance.inc.php,
zabbix-front-end-service-type): New variables.
* doc/guix.texi (Monitoring Services): Document this.
---
 doc/guix.texi               |  75 ++++++++++++++++++
 gnu/services/monitoring.scm | 146 +++++++++++++++++++++++++++++++++++-
 gnu/tests/monitoring.scm    |  49 ++++++++++++
 3 files changed, 269 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index d83071b432..a1de8b0f15 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -16854,6 +16854,81 @@ Defaults to @samp{()}.
 
 @end deftypevr
 
+@c %end of fragment
+
+@subsubheading Zabbix front-end
+@cindex zabbix zabbix-front-end
+
+This service provides a WEB interface to Zabbix server.
+
+@c %start of fragment
+
+Available @code{zabbix-front-end-configuration} fields are:
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} nginx-server-configuration-list nginx
+NGINX configuration.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} string db-host
+Database host name.
+
+Defaults to @samp{"localhost"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} number db-port
+Database port.
+
+Defaults to @samp{5432}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} string db-name
+Database name.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} string db-user
+Database user.
+
+Defaults to @samp{"zabbix"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} string db-password
+Database password.  Please, use @code{db-secret-file} instead.
+
+Defaults to @samp{""}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} string db-secret-file
+Secret file which will be appended to @file{zabbix.conf.php} file.  This
+file contains credentials for use by Zabbix front-end.  You are expected
+to create it manually.
+
+Defaults to @samp{""}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} string zabbix-host
+Zabbix server hostname.
+
+Defaults to @samp{"localhost"}.
+
+@end deftypevr
+
+@deftypevr {@code{zabbix-front-end-configuration} parameter} number zabbix-port
+Zabbix server port.
+
+Defaults to @samp{10051}.
+
+@end deftypevr
+
+
 @c %end of fragment
 
 @node Kerberos Services
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index 274228af89..452f26ef8a 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -22,6 +22,7 @@
   #:use-module (gnu services)
   #:use-module (gnu services configuration)
   #:use-module (gnu services shepherd)
+  #:use-module (gnu services web)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages monitoring)
   #:use-module (gnu system shadow)
@@ -29,6 +30,7 @@
   #:use-module (guix packages)
   #:use-module (guix records)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 rdelim)
   #:use-module (srfi srfi-26)
   #:export (darkstat-configuration
             prometheus-node-exporter-configuration
@@ -38,7 +40,10 @@
             zabbix-server-configuration
             zabbix-server-service-type
             zabbix-agent-configuration
-            zabbix-agent-service-type))
+            zabbix-agent-service-type
+            zabbix-front-end-configuration
+            zabbix-front-end-service-type
+            %zabbix-front-end-configuration-nginx))
 
 \f
 ;;;
@@ -174,6 +179,12 @@ prometheus.")
 (define (serialize-include-files field-name val)
   (if (null? val) "" (for-each (cut serialize-field 'include <>) val)))
 
+(define (nginx-server-configuration-list? val)
+  (and (list? val) (and-map nginx-server-configuration? val)))
+
+(define (serialize-nginx-server-configuration-list field-name val)
+  "")
+
 (define-configuration zabbix-server-configuration
   (zabbix-server
    (package zabbix-server)
@@ -439,3 +450,136 @@ configuration file."))
    `((zabbix-agent-configuration
       ,zabbix-agent-configuration-fields))
    'zabbix-agent-configuration))
+
+(define %zabbix-front-end-configuration-nginx
+  (nginx-server-configuration
+   (root #~(string-append #$zabbix-server:front-end "/share/zabbix/php"))
+   (index '("index.php"))
+   (locations
+    (let ((php-location (nginx-php-location)))
+      (list (nginx-location-configuration
+             (inherit php-location)
+             (body (append (nginx-location-configuration-body php-location)
+                           (list "
+fastcgi_param PHP_VALUE \"post_max_size = 16M
+                          max_execution_time = 300\";
+")))))))))
+
+(define-configuration zabbix-front-end-configuration
+  ;; TODO: Specify zabbix front-end package.
+  ;; (zabbix-
+  ;;  (package zabbix-front-end)
+  ;;  "The zabbix-front-end package.")
+  (nginx
+   (nginx-server-configuration-list
+    (list %zabbix-front-end-configuration-nginx))
+   "NGINX configuration.")
+  (db-host
+   (string "localhost")
+   "Database host name.")
+  (db-port
+   (number 5432)
+   "Database port.")
+  (db-name
+   (string "zabbix")
+   "Database name.")
+  (db-user
+   (string "zabbix")
+   "Database user.")
+  (db-password
+   (string "")
+   "Database password.  Please, use @code{db-secret-file} instead.")
+  (db-secret-file
+   (string "")
+   "Secret file which will be appended to @file{zabbix.conf.php} file.  This
+file contains credentials for use by Zabbix front-end.  You are expected to
+create it manually.")
+  (zabbix-host
+   (string "localhost")
+   "Zabbix server hostname.")
+  (zabbix-port
+   (number 10051)
+   "Zabbix server port."))
+
+(define zabbix-front-end-config
+  (match-lambda
+    (($ <zabbix-front-end-configuration>
+        _ db-host db-port db-name db-user db-password db-secret-file
+        zabbix-host zabbix-port)
+     (mixed-text-file "zabbix.conf.php"
+                      "\
+<?php
+// Zabbix GUI configuration file.
+global $DB;
+
+$DB['TYPE']     = 'POSTGRESQL';
+$DB['SERVER']   = '" db-host "';
+$DB['PORT']     = '" (number->string db-port) "';
+$DB['DATABASE'] = '" db-name "';
+$DB['USER']     = '" db-user "';
+$DB['PASSWORD'] = '" (if (string-null? db-password)
+                         (if (string-null? db-secret-file)
+                             (display "Provide a `db-secret-file' \
+or `db-password' field.
+"
+                                      (current-error-port))
+                             (string-trim-both
+                              (with-input-from-file db-secret-file
+                                read-string)))
+                         (begin
+                           (display "
+Hint: Consider use `db-secret-file' instead of `db-password' and unset
+`db-password' in `zabbix-front-end-configuration' for security.
+")
+                           db-password)) "';
+
+// Schema name. Used for IBM DB2 and PostgreSQL.
+$DB['SCHEMA'] = '';
+
+$ZBX_SERVER      = '" zabbix-host "';
+$ZBX_SERVER_PORT = '" (number->string zabbix-port) "';
+$ZBX_SERVER_NAME = '';
+
+$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
+"))))
+
+(define %maintenance.inc.php
+  ;; Empty php file to allow us move zabbix-frontend configs to ‘/etc/zabbix’
+  ;; directory.  See ‘install-front-end’ phase in
+  ;; (@ (gnu packages monitoring) zabbix-server) package.
+    "\
+<?php
+")
+
+(define (zabbix-front-end-activation config)
+  "Return the activation gexp for CONFIG."
+  #~(begin
+      (use-modules (guix build utils))
+      (mkdir-p "/etc/zabbix")
+      (call-with-output-file "/etc/zabbix/maintenance.inc.php"
+            (lambda (port)
+              (display #$%maintenance.inc.php port)))
+      (copy-file #$(zabbix-front-end-config config)
+                 "/etc/zabbix/zabbix.conf.php")))
+
+(define zabbix-front-end-service-type
+  (service-type
+   (name 'zabbix-front-end)
+   (extensions
+    (list (service-extension activation-service-type
+                             zabbix-front-end-activation)
+          (service-extension nginx-service-type
+                             zabbix-front-end-configuration-nginx)
+          ;; Make sure php-fpm is instantiated.
+          (service-extension php-fpm-service-type
+                             (const #t))))
+   (default-value (zabbix-front-end-configuration))
+   (description
+    "Run the zabbix-front-end web interface, which allows users to interact
+with Zabbix server.")))
+
+(define (generate-zabbix-front-end-documentation)
+  (generate-documentation
+   `((zabbix-front-end-configuration
+      ,zabbix-front-end-configuration-fields))
+   'zabbix-front-end-configuration))
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index ec9e086ff4..3169e5b66f 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
@@ -20,11 +20,13 @@
 (define-module (gnu tests monitoring)
   #:use-module (gnu packages databases)
   #:use-module (gnu packages monitoring)
+  #:use-module (gnu packages php)
   #:use-module (gnu services)
   #:use-module (gnu services monitoring)
   #:use-module (gnu services networking)
   #:use-module (gnu services databases)
   #:use-module (gnu services shepherd)
+  #:use-module (gnu services web)
   #:use-module (gnu system vm)
   #:use-module (gnu system)
   #:use-module (gnu tests)
@@ -250,6 +252,44 @@ zabbix||{}
              '(file-exists? "/var/run/zabbix/zabbix_agent.pid")
              marionette))
 
+          ;; Wait for php-fpm to be up and running.
+          (test-assert "php-fpm running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (start-service 'php-fpm))
+             marionette))
+
+          ;; Wait for nginx to be up and running.
+          (test-assert "nginx running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (start-service 'nginx))
+             marionette))
+
+          ;; Make sure the PID file is created.
+          (test-assert "nginx PID file"
+            (marionette-eval
+             '(file-exists? "/var/run/nginx/pid")
+             marionette))
+
+          ;; Make sure we can access pages that correspond to our repository.
+          (letrec-syntax ((test-url
+                           (syntax-rules ()
+                             ((_ path code)
+                              (test-equal (string-append "GET " path)
+                                code
+                                (let-values (((response body)
+                                              (http-get (string-append
+                                                         "http://localhost:8080"
+                                                         path))))
+                                  (response-code response))))
+                             ((_ path)
+                              (test-url path 200)))))
+            (test-url "/")
+            (test-url "/does-not-exist" 404))
+
           (test-end)
 
           (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
@@ -262,6 +302,15 @@ zabbix||{}
          (simple-operating-system
           (service dhcp-client-service-type)
           (postgresql-service)
+          (service zabbix-front-end-service-type
+                   (zabbix-front-end-configuration
+                    (db-password "zabbix")))
+
+          (service php-fpm-service-type
+                   (php-fpm-configuration
+                    (timezone "Europe/Paris")
+                    (php php-with-bcmath)))
+
           (service zabbix-server-service-type
                    (zabbix-server-configuration
                     (db-password "zabbix")
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* bug#33549: Status: [PATCH 0/6] Add Zabbix services.
  2018-11-29 18:47 [bug#33549] [PATCH 0/6] Add Zabbix services Oleg Pykhalov
  2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
@ 2018-12-17 19:22 ` Oleg Pykhalov
  1 sibling, 0 replies; 12+ messages in thread
From: Oleg Pykhalov @ 2018-12-17 19:22 UTC (permalink / raw)
  To: bug#33549

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

Hello Guix,

I pushed current patch series to master with a minor fix for
'extra-options' fields and update to a new Zabbix release.

f2f956010c64503daa18cf8138a3264212969c3d gnu: zabbix-agentd: Update to 4.0.2.
85c07cff9cd2197a16c2d3544e4930e278513cf7 services: monitoring: Add 'zabbix-front-end'.
1a3e7534d0a02fad1d19173985cf47e1aaa3b956 gnu: Add php-with-bcmath.
e517161d6b0ee544dab94477c9ffbad59cc1834b services: php-fpm: Add 'timezone' configuration.
6106d7cae49fb6686a237b53d465c89211ecad8f services: monitoring: Add 'zabbix-agent'.
6b1c4179e2596d860b1c49dea8021bc39d28da67 services: monitoring: Add 'zabbix-server'.
2c9ac8392ad867f65b1313216dbe7179d6083df5 gnu: zabbix-server: Split output.

Successfully tested with:

make check-system TESTS="zabbix"
make check-system TESTS="php-fpm"

Oleg.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 5/6] gnu: Add php-with-bcmath.
  2018-11-29 18:50   ` [bug#33549] [PATCH 5/6] gnu: Add php-with-bcmath Oleg Pykhalov
@ 2018-12-19 15:20     ` Ludovic Courtès
  0 siblings, 0 replies; 12+ messages in thread
From: Ludovic Courtès @ 2018-12-19 15:20 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33549

Hi Oleg,

Sorry for the late reply!

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> * gnu/packages/php.scm (php-with-bcmath): New variable.

[...]

> +(define-public php-with-bcmath
> +  (package
> +    (inherit php)
> +    (name "php-with-bcmath")
> +    (arguments
> +     (substitute-keyword-arguments (package-arguments php)
> +       ((#:configure-flags flags)
> +        `(cons "--enable-bcmath" ,flags))))))

Any reason not to make it the default ‘php’ package?

Ludo’.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end'.
  2018-11-29 18:50   ` [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end' Oleg Pykhalov
@ 2018-12-19 15:27     ` Ludovic Courtès
  2018-12-19 18:27       ` Oleg Pykhalov
  0 siblings, 1 reply; 12+ messages in thread
From: Ludovic Courtès @ 2018-12-19 15:27 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33549

Hi Oleg,

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> +(define zabbix-front-end-config
> +  (match-lambda
> +    (($ <zabbix-front-end-configuration>
> +        _ db-host db-port db-name db-user db-password db-secret-file
> +        zabbix-host zabbix-port)
> +     (mixed-text-file "zabbix.conf.php"
> +                      "\
> +<?php
> +// Zabbix GUI configuration file.
> +global $DB;
> +
> +$DB['TYPE']     = 'POSTGRESQL';
> +$DB['SERVER']   = '" db-host "';
> +$DB['PORT']     = '" (number->string db-port) "';
> +$DB['DATABASE'] = '" db-name "';
> +$DB['USER']     = '" db-user "';
> +$DB['PASSWORD'] = '" (if (string-null? db-password)
> +                         (if (string-null? db-secret-file)
> +                             (display "Provide a `db-secret-file' \
> +or `db-password' field.
> +"
> +                                      (current-error-port))
> +                             (string-trim-both
> +                              (with-input-from-file db-secret-file
> +                                read-string)))
> +                         (begin
> +                           (display "
> +Hint: Consider use `db-secret-file' instead of `db-password' and unset
> +`db-password' in `zabbix-front-end-configuration' for security.
> +")
> +                           db-password)) "';
> +
> +// Schema name. Used for IBM DB2 and PostgreSQL.
> +$DB['SCHEMA'] = '';
> +
> +$ZBX_SERVER      = '" zabbix-host "';
> +$ZBX_SERVER_PORT = '" (number->string zabbix-port) "';
> +$ZBX_SERVER_NAME = '';
> +
> +$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
> +"))))

I saw these “hints” in the build log of Cuirass and that got me curious.
:-)

A couple of comments…  For consistency, hints should be reported using
the ‘display-hint’ procedure, which takes a Texinfo string as input.

Second, while the second ‘display’ call does look like a hint, the first
one looks like it should be an error, shouldn’t it?  In that case, I’d
suggest something like:

  (raise (condition
           (&message
            (message "You must provide either 'db-secret-file' or 'db-password'."))))

Third, it would be nice to report source location info along with hints
and errors.  To do that, you could add an innate ‘location’ field to
<zabbix-front-end-configuration> as done for <package>.  Then, along
with the &message condition above, you could raise an &error-location as
is done in a few places.

Does that make sense?

Anyway thanks for this patch series, we’ll probably put it to good use
on the build farm!

Ludo’.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end'.
  2018-12-19 15:27     ` Ludovic Courtès
@ 2018-12-19 18:27       ` Oleg Pykhalov
  2018-12-20 11:06         ` Ludovic Courtès
  0 siblings, 1 reply; 12+ messages in thread
From: Oleg Pykhalov @ 2018-12-19 18:27 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 33549-done

[-- Attachment #1: Type: text/plain, Size: 2565 bytes --]

Hi Ludovic,

Thank you for review.

Ludovic Courtès <ludo@gnu.org> writes:

[…]

>> +$DB['PASSWORD'] = '" (if (string-null? db-password)
>> +                         (if (string-null? db-secret-file)
>> +                             (display "Provide a `db-secret-file' \
>> +or `db-password' field.
>> +"
>> +                                      (current-error-port))
>> +                             (string-trim-both
>> +                              (with-input-from-file db-secret-file
>> +                                read-string)))
>> +                         (begin
>> +                           (display "
>> +Hint: Consider use `db-secret-file' instead of `db-password' and unset
>> +`db-password' in `zabbix-front-end-configuration' for security.
>> +")
>> +                           db-password)) "';
>> +
>> +// Schema name. Used for IBM DB2 and PostgreSQL.
>> +$DB['SCHEMA'] = '';
>> +
>> +$ZBX_SERVER      = '" zabbix-host "';
>> +$ZBX_SERVER_PORT = '" (number->string zabbix-port) "';
>> +$ZBX_SERVER_NAME = '';
>> +
>> +$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
>> +"))))
>
> I saw these “hints” in the build log of Cuirass and that got me curious.
> :-)

Do you mean “hints” during ‘zabbix’ tests?

> A couple of comments…  For consistency, hints should be reported using
> the ‘display-hint’ procedure, which takes a Texinfo string as input.
>
> Second, while the second ‘display’ call does look like a hint, the first
> one looks like it should be an error, shouldn’t it?  In that case, I’d
> suggest something like:
>
>   (raise (condition
>            (&message
>             (message "You must provide either 'db-secret-file' or 'db-password'."))))

Thanks, pushed as 0485717ee94e7f161d072f017edce5d35df49c81 to master.

> Third, it would be nice to report source location info along with hints
> and errors.  To do that, you could add an innate ‘location’ field to
> <zabbix-front-end-configuration> as done for <package>.  Then, along
> with the &message condition above, you could raise an &error-location as
> is done in a few places.
>
> Does that make sense?

Sure.  I see innate location field in <package>, but unfortunately I'm
not sure how to implement it, because we use define-configuration for
<zabbix-front-end-configuration>.  So the implementation of that feature
may take a time.  ;-)

> Anyway thanks for this patch series, we’ll probably put it to good use
> on the build farm!

Feel free to ping me.


Oleg.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end'.
  2018-12-19 18:27       ` Oleg Pykhalov
@ 2018-12-20 11:06         ` Ludovic Courtès
  0 siblings, 0 replies; 12+ messages in thread
From: Ludovic Courtès @ 2018-12-20 11:06 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33549-done

Hi Oleg,

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> Ludovic Courtès <ludo@gnu.org> writes:
>
> […]
>
>>> +$DB['PASSWORD'] = '" (if (string-null? db-password)
>>> +                         (if (string-null? db-secret-file)
>>> +                             (display "Provide a `db-secret-file' \
>>> +or `db-password' field.
>>> +"
>>> +                                      (current-error-port))
>>> +                             (string-trim-both
>>> +                              (with-input-from-file db-secret-file
>>> +                                read-string)))
>>> +                         (begin
>>> +                           (display "
>>> +Hint: Consider use `db-secret-file' instead of `db-password' and unset
>>> +`db-password' in `zabbix-front-end-configuration' for security.
>>> +")
>>> +                           db-password)) "';
>>> +
>>> +// Schema name. Used for IBM DB2 and PostgreSQL.
>>> +$DB['SCHEMA'] = '';
>>> +
>>> +$ZBX_SERVER      = '" zabbix-host "';
>>> +$ZBX_SERVER_PORT = '" (number->string zabbix-port) "';
>>> +$ZBX_SERVER_NAME = '';
>>> +
>>> +$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
>>> +"))))
>>
>> I saw these “hints” in the build log of Cuirass and that got me curious.
>> :-)
>
> Do you mean “hints” during ‘zabbix’ tests?

Yes, in the output of the “evaluation” of the ‘guix-master’ jobset.

>> Third, it would be nice to report source location info along with hints
>> and errors.  To do that, you could add an innate ‘location’ field to
>> <zabbix-front-end-configuration> as done for <package>.  Then, along
>> with the &message condition above, you could raise an &error-location as
>> is done in a few places.
>>
>> Does that make sense?
>
> Sure.  I see innate location field in <package>, but unfortunately I'm
> not sure how to implement it, because we use define-configuration for
> <zabbix-front-end-configuration>.  So the implementation of that feature
> may take a time.  ;-)

We could probably change ‘define-configuration’ to add a ‘location’
field unconditionally.  But yeah, we’ll see!

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-12-20 11:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-29 18:47 [bug#33549] [PATCH 0/6] Add Zabbix services Oleg Pykhalov
2018-11-29 18:50 ` [bug#33549] [PATCH 1/6] gnu: zabbix-server: Split output Oleg Pykhalov
2018-11-29 18:50   ` [bug#33549] [PATCH 2/6] services: monitoring: Add 'zabbix-server' Oleg Pykhalov
2018-11-29 18:50   ` [bug#33549] [PATCH 3/6] services: monitoring: Add 'zabbix-agent' Oleg Pykhalov
2018-11-29 18:50   ` [bug#33549] [PATCH 4/6] services: php-fpm: Add 'timezone' configuration Oleg Pykhalov
2018-11-29 18:50   ` [bug#33549] [PATCH 5/6] gnu: Add php-with-bcmath Oleg Pykhalov
2018-12-19 15:20     ` Ludovic Courtès
2018-11-29 18:50   ` [bug#33549] [PATCH 6/6] services: monitoring: Add 'zabbix-front-end' Oleg Pykhalov
2018-12-19 15:27     ` Ludovic Courtès
2018-12-19 18:27       ` Oleg Pykhalov
2018-12-20 11:06         ` Ludovic Courtès
2018-12-17 19:22 ` bug#33549: Status: [PATCH 0/6] Add Zabbix services Oleg Pykhalov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).