pkgs/switch-report: init

This commit is contained in:
Astro 2022-10-23 22:39:06 +02:00
parent 3e84486651
commit 807f9d8e29
5 changed files with 90 additions and 4 deletions

View File

@ -104,6 +104,10 @@ let
inherit self nixpkgs system;
};
switch-report = import ./switch-report.nix {
inherit self nixpkgs system;
};
vlan-report = import ./vlan-report.nix {
inherit self nixpkgs system;
};
@ -115,6 +119,6 @@ in
rootfs-packages // vm-packages // device-templates // openwrt-packages // network-graphs // network-cypher-graphs // starlink // subnetplans // {
inherit export-openwrt-models export-config dns-slaves
encrypt-secrets decrypt-secrets switch-to-production
homepage gateway-report vlan-report
homepage gateway-report switch-report vlan-report
;
}

View File

@ -4,7 +4,7 @@ let
config = self.lib.config;
in
writeText "vlan-report.md" ''
writeText "gateway-report.md" ''
# Gateway Report
${lib.concatMapStrings (net:

View File

@ -12,7 +12,7 @@ let
inherit (self.packages.${system})
export-config
gateway-report network-graphs
subnetplans vlan-report;
subnetplans switch-report vlan-report;
in
stdenv.mkDerivation {
@ -30,8 +30,9 @@ stdenv.mkDerivation {
pandoc -t html ${../../../doc/hello.md} > index.html
cat ${./linked-data.html} >> index.html
pandoc -t html ${../../../doc/vpn.md} > vpn.html
pandoc -t html ${vlan-report} > vlan-report.html
pandoc -t html ${gateway-report} > gateway-report.html
pandoc -t html ${switch-report} > switch-report.html
pandoc -t html ${vlan-report} > vlan-report.html
echo '<pre>' > config.html
bat --color=always --theme=GitHub -p ${export-config} | \

View File

@ -25,6 +25,7 @@
<li><a href="vlan-report.html">VLAN</a></li>
<li><a href="logical.html">Logisch</a></li>
<li><a href="physical.html">Physisch</a></li>
<li><a href="switch-report.html">Ports</a></li>
<li><a href="vpn.html">VPN</a></li>
<li><a href="config.html">Config</a></li>
</ul>

View File

@ -0,0 +1,80 @@
{ 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}**
|Name|Ports|Group|Trunk|Networks|
|-:|-:|:-:|:-:|:-|
${lib.concatMapStrings (ports:
let
linkName = linksByPorts.${ports};
link = links.${linkName};
in ''
|**${
linkName
}**|${
ports
}|${
lib.optionalString (link.group != null) (
toString link.group
)
}|${
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"}
''