Storage
banshee/storage-collection/storage/netapp/https/ontap-9.6/
aggregates
The state and the space of each aggregate of a NetApp ONTAP cluster by its REST API.
by banshee1 installation2 versions
// The aggregates of a NetApp ONTAP cluster, by its REST API (GET /api/storage/aggregates), which ONTAP serves
// from 9.6: the state and the space of each.
// The address of the API is the cluster's management address, the host's: https://<host:address>/api/.
need('protocol:http');
$address = need('host:address');
$user = need('protocol:http:user');
$password = need('protocol:http:password');
per('aggregate', 'Aggregates');
output('state', 'text', array('label' => 'State', 'per' => 'aggregate'));
output('used', 'number', array('label' => 'Used space', 'unit' => '%', 'per' => 'aggregate'));
output('free', 'number', array('label' => 'Free space', 'unit' => 'GiB', 'per' => 'aggregate'));
output('size', 'number', array('label' => 'Size', 'unit' => 'GiB', 'per' => 'aggregate'));
watch.state('failed', 'Aggregate failed', 'state', array('critical' => array('offline', 'failed', 'inconsistent', 'unmounted', 'restricted')));
watch.expect('not-online', 'Aggregate not online', 'state', array('warning' => array('online')));
watch.above('used', 'Used space', 'used', array('warning' => 85, 'critical' => 95));
watch.above('full-soon', 'Full within a week', 'used', array('warning' => 99, 'ahead' => '7 d'));
watch.missing('missing', 'Aggregate missing', 'state', array('enabled' => false));
// One page of records at a time: ONTAP gives the next page's path under _links.next.href when it cuts the
// list, until the last. The password goes in Basic: the answer is not secret.
$path = '/api/storage/aggregates?fields=name,state,space.block_storage.size,space.block_storage.used,space.block_storage.available&max_records=1000';
$aggregates = array();
while ($path != '') {
$answer = http.get('https://' . $address . $path, user=$user, password=$password);
if ($answer['status'] == 401 || $answer['status'] == 403) {
fail('misconfigured', 'ONTAP refuses the account, code ' . $answer['status']);
}
if ($answer['status'] != 200) {
fail('unreachable', 'The ONTAP API answers code ' . $answer['status'],
'ONTAP serves its REST API from 9.6.');
}
$page = json.read($answer['body']);
foreach ($page['records'] as $record) {
$aggregates = list.add($aggregates, $record);
}
$path = '';
$links = list.get($page, '_links', array());
if (list.has($links, 'next')) {
$path = $links['next']['href'];
}
}
if (list.count($aggregates) == 0) {
fail('misconfigured', 'The ONTAP API lists no aggregate');
}
// {"name": "aggr1", "state": "online", "space": {"block_storage": {"size": 10995116277760, "used":
// 4398046511104, "available": 6597069766656}}}, in bytes. An aggregate that is not online may have no space.
foreach ($aggregates as $aggregate) {
$name = $aggregate['name'];
value('state', $aggregate['state'], $name);
$space = list.get(list.get($aggregate, 'space', array()), 'block_storage', array());
if (!list.has($space, 'size') || !list.has($space, 'used') || !list.has($space, 'available') || $space['size'] <= 0) {
continue;
}
value('used', number.round(100 * $space['used'] / $space['size'], 1), $name);
value('free', number.round($space['available'] / 1073741824, 1), $name);
value('size', number.round($space['size'] / 1073741824, 1), $name);
}