banshee is under active development: collectors will keep changing, and a version you publish will likely need adjustments. For stable use, wait for version 1.0.0.

Active Directory

banshee/active-directory-collection/active-directory/ssh/

dhcp-scopes

The use of each IPv4 scope of a Windows DHCP Server, by SSH and PowerShell

  • active-directory
  • dhcp
  • scopes
  • ssh
  • powershell

by banshee1 installation2 versions

Keen 1.0.0 · 39 lines
// The IPv4 scopes of the DHCP Server of Windows, by SSH: for each scope, the share of its addresses in use,
// and the addresses free and in use. A full scope leaves new clients without an address.
// Runs one PowerShell command that only reads, by the cmdlet Get-DhcpServerv4ScopeStatistics of the
// DhcpServer module, whose objects are those of the WMI class DhcpServerv4ScopeStatistics that Microsoft
// documents: ScopeId, PercentageInUse, AddressesFree, AddressesInUse. A scope is named by its identifier,
// the address of its network: "192.0.2.0".
need('protocol:ssh');

per('scope', 'Scopes');
output('used', 'number', array('label' => 'Addresses in use', 'unit' => '%', 'per' => 'scope'));
output('free', 'number', array('label' => 'Addresses free', 'per' => 'scope'));
output('in-use', 'number', array('label' => 'Addresses leased', 'per' => 'scope'));

watch.above('full', 'Scope nearly full', 'used', array('warning' => 85, 'critical' => 95));
watch.missing('missing', 'Scope missing', 'used');

$read = ssh.run("powershell -NoProfile -NonInteractive -Command \""
    . "$ErrorActionPreference = 'Stop'; "
    . "[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding; "
    . "ConvertTo-Json -Compress -Depth 4 -InputObject @{"
    . "scopes = @(Get-DhcpServerv4ScopeStatistics | ForEach-Object {"
    . " @{scope = [string]$_.ScopeId; used = $_.PercentageInUse;"
    . " free = $_.AddressesFree; inuse = $_.AddressesInUse} })}\"");
$answer = text.trim($read['output']);
if (list.count(text.match($answer, '^\{')) == 0) {
    fail('misconfigured', 'PowerShell did not return the DHCP scopes', $answer . $read['errors']);
}
$dhcp = json.read($answer);

$scopes = 0;
foreach ($dhcp['scopes'] as $scope) {
    $scopes = $scopes + 1;
    value('used', number.round($scope['used'], 1), $scope['scope']);
    value('free', $scope['free'], $scope['scope']);
    value('in-use', $scope['inuse'], $scope['scope']);
}
if ($scopes == 0) {
    fail('misconfigured', 'The DHCP Server has no IPv4 scope', $answer);
}