2022-10-23 22:39:06 +02:00
|
|
|
{ self, nixpkgs, system }:
|
|
|
|
with nixpkgs.legacyPackages.${system};
|
|
|
|
let
|
|
|
|
config = self.lib.config;
|
|
|
|
|
|
|
|
reportHosts = lib.concatMapStrings (hostName:
|
|
|
|
let
|
|
|
|
inherit (config.site.hosts.${hostName}) links model location;
|
|
|
|
|
|
|
|
linksByPorts = builtins.foldl' (linksByPorts: linkName:
|
|
|
|
if links.${linkName}.group != null
|
|
|
|
then
|
|
|
|
# group ports
|
|
|
|
linksByPorts // {
|
|
|
|
${lib.concatStringsSep "<br>" links.${linkName}.ports} = linkName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
# expand lists of access ports to seperate rows
|
|
|
|
builtins.foldl' (linksByPorts': port:
|
|
|
|
linksByPorts' // {
|
|
|
|
${port} = linkName;
|
|
|
|
}
|
|
|
|
) linksByPorts links.${linkName}.ports
|
|
|
|
) {} (builtins.attrNames links);
|
|
|
|
|
|
|
|
in ''
|
|
|
|
## ${hostName}
|
|
|
|
|
|
|
|
`${model}` @ **${location}**
|
|
|
|
|
2022-10-23 23:03:04 +02:00
|
|
|
|Name|Ports|Trunk|Networks|
|
|
|
|
|-:|-:|:-:|:-|
|
2022-10-23 22:39:06 +02:00
|
|
|
${lib.concatMapStrings (ports:
|
|
|
|
let
|
|
|
|
linkName = linksByPorts.${ports};
|
|
|
|
link = links.${linkName};
|
|
|
|
in ''
|
2022-10-23 23:03:04 +02:00
|
|
|
|${
|
|
|
|
lib.optionalString (link.group != null)
|
|
|
|
"Group ${toString link.group}: "
|
|
|
|
}**${
|
2022-10-23 22:39:06 +02:00
|
|
|
linkName
|
|
|
|
}**|${
|
|
|
|
ports
|
|
|
|
}|${
|
|
|
|
lib.optionalString link.trunk "✓"
|
|
|
|
}|${
|
|
|
|
lib.concatStringsSep "<br>" (
|
|
|
|
map (net:
|
|
|
|
"${net} (`${toString config.site.net.${net}.vlan}`)"
|
|
|
|
) (builtins.sort (a: b:
|
|
|
|
config.site.net.${a}.vlan < config.site.net.${b}.vlan
|
|
|
|
) link.nets)
|
|
|
|
)
|
|
|
|
}|
|
|
|
|
'') (lib.naturalSort (
|
|
|
|
builtins.attrNames linksByPorts
|
|
|
|
))}
|
|
|
|
|
|
|
|
'');
|
|
|
|
|
|
|
|
reportRole = role:
|
|
|
|
reportHosts (
|
|
|
|
lib.naturalSort (
|
|
|
|
builtins.filter (hostName:
|
|
|
|
config.site.hosts.${hostName}.role == "switch"
|
|
|
|
) (builtins.attrNames config.site.hosts)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
writeText "switch-report.md" ''
|
|
|
|
# Switch Report
|
|
|
|
|
|
|
|
${reportRole "switch"}
|
|
|
|
|
|
|
|
# Access Point Report
|
|
|
|
|
|
|
|
${reportRole "ap"}
|
|
|
|
''
|