@@ -603,6 +603,66 @@ let
603603 '';
604604 };
605605
606+ openldap = {
607+ exporterConfig = {
608+ enable = true;
609+ ldapCredentialFile = "${pkgs.writeText "exporter.yml" ''
610+ ldapUser: "cn=root,dc=example"
611+ ldapPass: "notapassword"
612+ ''}";
613+ };
614+ metricProvider = {
615+ services.openldap = {
616+ enable = true;
617+ settings.children = {
618+ "cn=schema".includes = [
619+ "${pkgs.openldap}/etc/schema/core.ldif"
620+ "${pkgs.openldap}/etc/schema/cosine.ldif"
621+ "${pkgs.openldap}/etc/schema/inetorgperson.ldif"
622+ "${pkgs.openldap}/etc/schema/nis.ldif"
623+ ];
624+ "olcDatabase={1}mdb" = {
625+ attrs = {
626+ objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
627+ olcDatabase = "{1}mdb";
628+ olcDbDirectory = "/var/db/openldap";
629+ olcSuffix = "dc=example";
630+ olcRootDN = {
631+ # cn=root,dc=example
632+ base64 = "Y249cm9vdCxkYz1leGFtcGxl";
633+ };
634+ olcRootPW = {
635+ path = "${pkgs.writeText "rootpw" "notapassword"}";
636+ };
637+ };
638+ };
639+ "olcDatabase={2}monitor".attrs = {
640+ objectClass = [ "olcDatabaseConfig" ];
641+ olcDatabase = "{2}monitor";
642+ olcAccess = [ "to dn.subtree=cn=monitor by users read" ];
643+ };
644+ };
645+ declarativeContents."dc=example" = ''
646+ dn: dc=example
647+ objectClass: domain
648+ dc: example
649+
650+ dn: ou=users,dc=example
651+ objectClass: organizationalUnit
652+ ou: users
653+ '';
654+ };
655+ };
656+ exporterTest = ''
657+ wait_for_unit("prometheus-openldap-exporter.service")
658+ wait_for_open_port(389)
659+ wait_for_open_port(9330)
660+ wait_until_succeeds(
661+ "curl -sSf http://localhost:9330/metrics | grep -q 'openldap_scrape{result=\"ok\"} 1'"
662+ )
663+ '';
664+ };
665+
606666 openvpn = {
607667 exporterConfig = {
608668 enable = true;