diff --git a/scripts/json-app-tool.php b/scripts/json-app-tool.php index 20cebe02d3..58ee5c84b6 100755 --- a/scripts/json-app-tool.php +++ b/scripts/json-app-tool.php @@ -34,7 +34,7 @@ function string_to_oid($string) }//end string_to_oid() // Options! -$short_opts = 'S:sktmlhj:a:'; +$short_opts = 'S:sktmlhj:a:d:'; $options = getopt($short_opts); // print the help @@ -48,6 +48,7 @@ if (isset($options['h'])) { -k If m is specified, just print the keys in tested order. -a The application name for use with -s and -t. -S SNMP extend name. Defaults to the same as -a. + -d JSON file to use for app data. -h Show this help text. -j must always be specified. @@ -197,6 +198,20 @@ if (isset($options['t'])) { 'app_type' => $options['a'], ]; } + // if d is specified, try to read it in and add it + if (isset($options['d'])) { + $raw_app_data = file_get_contents($options['d']); + if ($raw_json === false) { + exit(2); + } + $app_data = json_decode(stripslashes($raw_app_data), true); + if (json_last_error() !== JSON_ERROR_NONE) { + echo "Parsing '" . $options['d'] . "' failed. Running jsonlint...\n\n"; + system('jsonlint ' . escapeshellarg($options['j'])); + exit(3); + } + $test_data['applications']['poller']['applications']['0']['data'] = json_encode($app_data); + } echo json_encode($test_data, JSON_PRETTY_PRINT) . "\n"; exit(0); }