aboutsummaryrefslogtreecommitdiff
path: root/pkgs/servers/monitoring/plugins/wmiplus/default.nix
blob: 9a4e5d706e93bc45596f112c3a7c7d020afd7418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ stdenv, fetchFromGitHub, makeWrapper, perlPackages, txt2man
, monitoring-plugins
, wmic-bin ? null }:

stdenv.mkDerivation rec {
  pname = "check-wmiplus";
  version = "1.64";

  # We fetch from github.com instead of the proper upstream as nix-build errors
  # out with 406 when trying to fetch the sources
  src = fetchFromGitHub {
    owner = "speartail";
    repo = "checkwmiplus";
    rev = "v${version}";
    sha256 = "1m36rd2wnc5dk4mm9q4ch67w19144dl112p9s6lhc1sh6h25ln6r";
  };

  patches = [
    ./wmiplus_fix_manpage.patch
  ];

  propagatedBuildInputs = with perlPackages; [
    BHooksEndOfScope ClassDataInheritable ClassInspector ClassSingleton
    ConfigIniFiles DateTime DateTimeLocale DateTimeTimeZone DevelStackTrace
    EvalClosure ExceptionClass FileShareDir ModuleImplementation ModuleRuntime
    MROCompat namespaceautoclean namespaceclean NumberFormat PackageStash
    ParamsValidate ParamsValidationCompiler RoleTiny Specio
    SubExporterProgressive SubIdentify TryTiny
  ];

  nativeBuildInputs = [ makeWrapper txt2man ];

  dontConfigure = true;
  dontBuild = true;
  doCheck = false; # no checks

  postPatch = ''
    substituteInPlace check_wmi_plus.pl \
      --replace /usr/bin/wmic                      ${wmic-bin}/bin/wmic \
      --replace /etc/check_wmi_plus                $out/etc/check_wmi_plus \
      --replace /opt/nagios/bin/plugins            $out/etc/check_wmi_plus \
      --replace /usr/lib/nagios/plugins            ${monitoring-plugins}/libexec \
      --replace '$base_dir/check_wmi_plus_help.pl' "$out/bin/check_wmi_plus_help.pl"

    for f in *.pl ; do
      substituteInPlace $f --replace /usr/bin/perl ${perlPackages.perl}/bin/perl
    done
  '';

  installPhase = ''
    runHook preInstall

    install -Dm755 -t $out/bin *.pl
    install -Dm644 -t $out/share/doc/${pname} *.txt
    cp -r etc $out/

    runHook postInstall
  '';

  # 1. we need to wait until the main binary has been fixed up with proper perl paths before we can run it to generate the man page
  # 2. txt2man returns exit code 3 even if it works, so we add the || true bit
  postFixup = ''
    wrapProgram $out/bin/check_wmi_plus.pl \
      --set PERL5LIB "${perlPackages.makePerlPath propagatedBuildInputs}"

    mkdir -p $out/share/man/man1
    $out/bin/check_wmi_plus.pl --help | txt2man -d 1970-01-01 -s 1 -t check_wmi_plus -r "Check WMI Plus ${version}" > $out/share/man/man1/check_wmi_plus.1 || true
    gzip $out/share/man/man1/check_wmi_plus.1
  '';

  meta = with stdenv.lib; {
    description = "A sensu/nagios plugin using WMI to query Windows hosts";
    homepage = "http://edcint.co.nz/checkwmiplus";
    license = licenses.gpl2;
    maintainers = with maintainers; [ peterhoeg ];
  };
}