1<?php 2 3use LibreNMS\Exceptions\JsonAppException; 4use LibreNMS\Exceptions\JsonAppMissingKeysException; 5use LibreNMS\RRD\RrdDefinition; 6 7$name = 'certificate'; 8$app_id = $app['app_id']; 9$output = 'OK'; 10 11try { 12 $certificate_data = json_app_get($device, $name, 1)['data']; 13} catch (JsonAppMissingKeysException $e) { 14 $certificate_data = $e->getParsedJson(); 15} catch (JsonAppException $e) { 16 echo PHP_EOL . $name . ':' . $e->getCode() . ':' . $e->getMessage() . PHP_EOL; 17 update_application($app, $e->getCode() . ':' . $e->getMessage(), []); // Set empty metrics and error message 18 19 return; 20} 21 22$rrd_name = ['app', $name, $app_id]; 23$rrd_def = RrdDefinition::make() 24 ->addDataset('age', 'GAUGE', 0) 25 ->addDataset('remaining_days', 'GAUGE', 0); 26 27$metrics = []; 28foreach ($certificate_data as $data) { 29 $cert_name = $data['cert_name']; 30 $age = $data['age']; 31 $remaining_days = $data['remaining_days']; 32 33 $rrd_name = ['app', $name, $app_id, $cert_name]; 34 35 $fields = [ 36 'age' => $age, 37 'remaining_days' => $remaining_days, 38 ]; 39 40 $metrics[$cert_name] = $fields; 41 $tags = ['name' => $cert_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name]; 42 data_update($device, 'app', $tags, $fields); 43} 44 45update_application($app, $output, $metrics); 46