aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/logging
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/services/logging')
-rw-r--r--nixpkgs/nixos/modules/services/logging/awstats.nix298
-rw-r--r--nixpkgs/nixos/modules/services/logging/logcheck.nix7
-rw-r--r--nixpkgs/nixos/modules/services/logging/logstash.nix5
-rw-r--r--nixpkgs/nixos/modules/services/logging/syslog-ng.nix4
4 files changed, 232 insertions, 82 deletions
diff --git a/nixpkgs/nixos/modules/services/logging/awstats.nix b/nixpkgs/nixos/modules/services/logging/awstats.nix
index a92ff3bee49..5939d7808f7 100644
--- a/nixpkgs/nixos/modules/services/logging/awstats.nix
+++ b/nixpkgs/nixos/modules/services/logging/awstats.nix
@@ -4,31 +4,117 @@ with lib;
let
cfg = config.services.awstats;
- httpd = config.services.httpd;
package = pkgs.awstats;
-in
+ configOpts = {name, config, ...}: {
+ options = {
+ type = mkOption{
+ type = types.enum [ "mail" "web" ];
+ default = "web";
+ example = "mail";
+ description = ''
+ The type of log being collected.
+ '';
+ };
+ domain = mkOption {
+ type = types.str;
+ default = name;
+ description = "The domain name to collect stats for.";
+ example = "example.com";
+ };
+
+ logFile = mkOption {
+ type = types.str;
+ example = "/var/spool/nginx/logs/access.log";
+ description = ''
+ The log file to be scanned.
+ For mail, set this to
+ <literal>
+ journalctl $OLD_CURSOR -u postfix.service | ''${pkgs.perl}/bin/perl ''${pkgs.awstats.out}/share/awstats/tools/maillogconvert.pl standard |
+ </literal>
+ '';
+ };
+
+ logFormat = mkOption {
+ type = types.str;
+ default = "1";
+ description = ''
+ The log format being used.
+
+ For mail, set this to
+ <literal>
+ %time2 %email %email_r %host %host_r %method %url %code %bytesd
+ </literal>
+ '';
+ };
+
+ hostAliases = mkOption {
+ type = types.listOf types.str;
+ default = [];
+ example = "[ \"www.example.org\" ]";
+ description = ''
+ List of aliases the site has.
+ '';
+ };
+
+ extraConfig = mkOption {
+ type = types.attrsOf types.str;
+ default = {};
+ example = literalExample ''
+ {
+ "ValidHTTPCodes" = "404";
+ }
+ '';
+ description = "Extra configuration to be appendend to awstats.\${name}.conf.";
+ };
+
+ webService = {
+ enable = mkEnableOption "awstats web service";
+
+ hostname = mkOption {
+ type = types.str;
+ default = config.domain;
+ description = "The hostname the web service appears under.";
+ };
+
+ urlPrefix = mkOption {
+ type = types.str;
+ default = "/awstats";
+ description = "The URL prefix under which the awstats pages appear.";
+ };
+ };
+ };
+ };
+ webServices = filterAttrs (name: value: value.webService.enable) cfg.configs;
+in
{
+ imports = [
+ (mkRemovedOptionModule [ "services" "awstats" "service" "enable" ] "Please enable per domain with `services.awstats.configs.<name>.webService.enable`")
+ (mkRemovedOptionModule [ "services" "awstats" "service" "urlPrefix" ] "Please set per domain with `services.awstats.configs.<name>.webService.urlPrefix`")
+ (mkRenamedOptionModule [ "services" "awstats" "vardir" ] [ "services" "awstats" "dataDir" ])
+ ];
+
options.services.awstats = {
- enable = mkOption {
- type = types.bool;
- default = cfg.service.enable;
- description = ''
- Enable the awstats program (but not service).
- Currently only simple httpd (Apache) configs are supported,
- and awstats plugins may not work correctly.
- '';
- };
- vardir = mkOption {
+ enable = mkEnableOption "awstats";
+
+ dataDir = mkOption {
type = types.path;
default = "/var/lib/awstats";
- description = "The directory where variable awstats data will be stored.";
+ description = "The directory where awstats data will be stored.";
};
- extraConfig = mkOption {
- type = types.lines;
- default = "";
- description = "Extra configuration to be appendend to awstats.conf.";
+ configs = mkOption {
+ type = types.attrsOf (types.submodule configOpts);
+ default = {};
+ example = literalExample ''
+ {
+ "mysite" = {
+ domain = "example.com";
+ logFile = "/var/spool/nginx/logs/access.log";
+ };
+ }
+ '';
+ description = "Attribute set of domains to collect stats for.";
};
updateAt = mkOption {
@@ -42,75 +128,129 @@ in
<manvolnum>7</manvolnum></citerefentry>)
'';
};
-
- service = {
- enable = mkOption {
- type = types.bool;
- default = false;
- description = ''Enable the awstats web service. This switches on httpd.'';
- };
- urlPrefix = mkOption {
- type = types.str;
- default = "/awstats";
- description = "The URL prefix under which the awstats service appears.";
- };
- };
};
config = mkIf cfg.enable {
environment.systemPackages = [ package.bin ];
- /* TODO:
- - heed config.services.httpd.logPerVirtualHost, etc.
- - Can't AllowToUpdateStatsFromBrowser, as CGI scripts don't have permission
- to read the logs, and our httpd config apparently doesn't an option for that.
- */
- environment.etc."awstats/awstats.conf".source = pkgs.runCommand "awstats.conf"
+
+ environment.etc = mapAttrs' (name: opts:
+ nameValuePair "awstats/awstats.${name}.conf" {
+ source = pkgs.runCommand "awstats.${name}.conf"
{ preferLocalBuild = true; }
- ( let
- logFormat =
- if httpd.logFormat == "combined" then "1" else
- if httpd.logFormat == "common" then "4" else
- throw "awstats service doesn't support Apache log format `${httpd.logFormat}`";
- in
- ''
- sed \
- -e 's|^\(DirData\)=.*$|\1="${cfg.vardir}"|' \
- -e 's|^\(DirIcons\)=.*$|\1="icons"|' \
- -e 's|^\(CreateDirDataIfNotExists\)=.*$|\1=1|' \
- -e 's|^\(SiteDomain\)=.*$|\1="${httpd.hostName}"|' \
- -e 's|^\(LogFile\)=.*$|\1="${httpd.logDir}/access_log"|' \
- -e 's|^\(LogFormat\)=.*$|\1=${logFormat}|' \
- < '${package.out}/wwwroot/cgi-bin/awstats.model.conf' > "$out"
- echo '${cfg.extraConfig}' >> "$out"
- '');
-
- systemd.tmpfiles.rules = optionals cfg.service.enable [
- "d '${cfg.vardir}' - ${httpd.user} ${httpd.group} - -"
- "Z '${cfg.vardir}' - ${httpd.user} ${httpd.group} - -"
- ];
-
- # The httpd sub-service showing awstats.
- services.httpd = optionalAttrs cfg.service.enable {
- enable = true;
- extraConfig = ''
- Alias ${cfg.service.urlPrefix}/classes "${package.out}/wwwroot/classes/"
- Alias ${cfg.service.urlPrefix}/css "${package.out}/wwwroot/css/"
- Alias ${cfg.service.urlPrefix}/icons "${package.out}/wwwroot/icon/"
- ScriptAlias ${cfg.service.urlPrefix}/ "${package.out}/wwwroot/cgi-bin/"
-
- <Directory "${package.out}/wwwroot">
- Options None
- Require all granted
- </Directory>
- '';
- };
+ (''
+ sed \
+ ''
+ # set up mail stats
+ + optionalString (opts.type == "mail")
+ ''
+ -e 's|^\(LogType\)=.*$|\1=M|' \
+ -e 's|^\(LevelForBrowsersDetection\)=.*$|\1=0|' \
+ -e 's|^\(LevelForOSDetection\)=.*$|\1=0|' \
+ -e 's|^\(LevelForRefererAnalyze\)=.*$|\1=0|' \
+ -e 's|^\(LevelForRobotsDetection\)=.*$|\1=0|' \
+ -e 's|^\(LevelForSearchEnginesDetection\)=.*$|\1=0|' \
+ -e 's|^\(LevelForFileTypesDetection\)=.*$|\1=0|' \
+ -e 's|^\(LevelForWormsDetection\)=.*$|\1=0|' \
+ -e 's|^\(ShowMenu\)=.*$|\1=1|' \
+ -e 's|^\(ShowSummary\)=.*$|\1=HB|' \
+ -e 's|^\(ShowMonthStats\)=.*$|\1=HB|' \
+ -e 's|^\(ShowDaysOfMonthStats\)=.*$|\1=HB|' \
+ -e 's|^\(ShowDaysOfWeekStats\)=.*$|\1=HB|' \
+ -e 's|^\(ShowHoursStats\)=.*$|\1=HB|' \
+ -e 's|^\(ShowDomainsStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowHostsStats\)=.*$|\1=HB|' \
+ -e 's|^\(ShowAuthenticatedUsers\)=.*$|\1=0|' \
+ -e 's|^\(ShowRobotsStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowEMailSenders\)=.*$|\1=HBML|' \
+ -e 's|^\(ShowEMailReceivers\)=.*$|\1=HBML|' \
+ -e 's|^\(ShowSessionsStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowPagesStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowFileTypesStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowFileSizesStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowBrowsersStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowOSStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowOriginStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowKeyphrasesStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowKeywordsStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowMiscStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowHTTPErrorsStats\)=.*$|\1=0|' \
+ -e 's|^\(ShowSMTPErrorsStats\)=.*$|\1=1|' \
+ ''
+ +
+ # common options
+ ''
+ -e 's|^\(DirData\)=.*$|\1="${cfg.dataDir}/${name}"|' \
+ -e 's|^\(DirIcons\)=.*$|\1="icons"|' \
+ -e 's|^\(CreateDirDataIfNotExists\)=.*$|\1=1|' \
+ -e 's|^\(SiteDomain\)=.*$|\1="${name}"|' \
+ -e 's|^\(LogFile\)=.*$|\1="${opts.logFile}"|' \
+ -e 's|^\(LogFormat\)=.*$|\1="${opts.logFormat}"|' \
+ ''
+ +
+ # extra config
+ concatStringsSep "\n" (mapAttrsToList (n: v: ''
+ -e 's|^\(${n}\)=.*$|\1="${v}"|' \
+ '') opts.extraConfig)
+ +
+ ''
+ < '${package.out}/wwwroot/cgi-bin/awstats.model.conf' > "$out"
+ '');
+ }) cfg.configs;
- systemd.services.awstats-update = mkIf (cfg.updateAt != null) {
- description = "awstats log collector";
- script = "exec '${package.bin}/bin/awstats' -update -config=awstats.conf";
- startAt = cfg.updateAt;
- };
+ # create data directory with the correct permissions
+ systemd.tmpfiles.rules =
+ [ "d '${cfg.dataDir}' 755 root root - -" ] ++
+ mapAttrsToList (name: opts: "d '${cfg.dataDir}/${name}' 755 root root - -") cfg.configs ++
+ [ "Z '${cfg.dataDir}' 755 root root - -" ];
+
+ # nginx options
+ services.nginx.virtualHosts = mapAttrs'(name: opts: {
+ name = opts.webService.hostname;
+ value = {
+ locations = {
+ "${opts.webService.urlPrefix}/css/" = {
+ alias = "${package.out}/wwwroot/css/";
+ };
+ "${opts.webService.urlPrefix}/icons/" = {
+ alias = "${package.out}/wwwroot/icon/";
+ };
+ "${opts.webService.urlPrefix}/" = {
+ alias = "${cfg.dataDir}/${name}/";
+ extraConfig = ''
+ autoindex on;
+ '';
+ };
+ };
+ };
+ }) webServices;
+
+ # update awstats
+ systemd.services = mkIf (cfg.updateAt != null) (mapAttrs' (name: opts:
+ nameValuePair "awstats-${name}-update" {
+ description = "update awstats for ${name}";
+ script = optionalString (opts.type == "mail")
+ ''
+ if [[ -f "${cfg.dataDir}/${name}-cursor" ]]; then
+ CURSOR="$(cat "${cfg.dataDir}/${name}-cursor" | tr -d '\n')"
+ if [[ -n "$CURSOR" ]]; then
+ echo "Using cursor: $CURSOR"
+ export OLD_CURSOR="--cursor $CURSOR"
+ fi
+ fi
+ NEW_CURSOR="$(journalctl $OLD_CURSOR -u postfix.service --show-cursor | tail -n 1 | tr -d '\n' | sed -e 's#^-- cursor: \(.*\)#\1#')"
+ echo "New cursor: $NEW_CURSOR"
+ ${package.bin}/bin/awstats -update -config=${name}
+ if [ -n "$NEW_CURSOR" ]; then
+ echo -n "$NEW_CURSOR" > ${cfg.dataDir}/${name}-cursor
+ fi
+ '' + ''
+ ${package.out}/share/awstats/tools/awstats_buildstaticpages.pl \
+ -config=${name} -update -dir=${cfg.dataDir}/${name} \
+ -awstatsprog=${package.bin}/bin/awstats
+ '';
+ startAt = cfg.updateAt;
+ }) cfg.configs);
};
}
diff --git a/nixpkgs/nixos/modules/services/logging/logcheck.nix b/nixpkgs/nixos/modules/services/logging/logcheck.nix
index 6d8be5b926d..4296b2270c2 100644
--- a/nixpkgs/nixos/modules/services/logging/logcheck.nix
+++ b/nixpkgs/nixos/modules/services/logging/logcheck.nix
@@ -213,13 +213,14 @@ in
mapAttrsToList writeIgnoreRule cfg.ignore
++ mapAttrsToList writeIgnoreCronRule cfg.ignoreCron;
- users.users = optionalAttrs (cfg.user == "logcheck") (singleton
- { name = "logcheck";
+ users.users = optionalAttrs (cfg.user == "logcheck") {
+ logcheck = {
uid = config.ids.uids.logcheck;
shell = "/bin/sh";
description = "Logcheck user account";
extraGroups = cfg.extraGroups;
- });
+ };
+ };
system.activationScripts.logcheck = ''
mkdir -m 700 -p /var/{lib,lock}/logcheck
diff --git a/nixpkgs/nixos/modules/services/logging/logstash.nix b/nixpkgs/nixos/modules/services/logging/logstash.nix
index 4943e8d7db3..21a83803fd8 100644
--- a/nixpkgs/nixos/modules/services/logging/logstash.nix
+++ b/nixpkgs/nixos/modules/services/logging/logstash.nix
@@ -37,6 +37,11 @@ let
in
{
+ imports = [
+ (mkRenamedOptionModule [ "services" "logstash" "address" ] [ "services" "logstash" "listenAddress" ])
+ (mkRemovedOptionModule [ "services" "logstash" "enableWeb" ] "The web interface was removed from logstash")
+ ];
+
###### interface
options = {
diff --git a/nixpkgs/nixos/modules/services/logging/syslog-ng.nix b/nixpkgs/nixos/modules/services/logging/syslog-ng.nix
index 65e103ac2ba..35055311680 100644
--- a/nixpkgs/nixos/modules/services/logging/syslog-ng.nix
+++ b/nixpkgs/nixos/modules/services/logging/syslog-ng.nix
@@ -25,6 +25,10 @@ let
];
in {
+ imports = [
+ (mkRemovedOptionModule [ "services" "syslog-ng" "serviceName" ] "")
+ (mkRemovedOptionModule [ "services" "syslog-ng" "listenToJournal" ] "")
+ ];
options = {