3 defined('SYSPATH') or die('No direct access allowed.');
6 * Helper methods for performance data processing.
8 * This should only be used in ORM, to do the backend processing. Because this
9 * can be done both for services and hosts, which is entirely similar, this is
10 * exported to a helper, so it's available for both.
12 class performance_data
{
14 * Process performance data and return as an array
16 * @param $perf_data_str string
19 public static function process_performance_data($perf_data_str) {
20 /* Split string in data soruce part and performance part */
22 "/(?<=^|[\\s])('(?:\\\\.|[^\\\\'])*'|[^'\\s=][^\\s=]*)=([-0-9.]*|U)([%a-zA-Z]*)(?:;([^; ]*)(?:;([^; ]*)(?:;([-0-9.]*)(?:;([-0-9.]*)|)|)|)|)(?=$|[\\s])/",
23 $perf_data_str, $matches, PREG_SET_ORDER
);
25 $perf_data = array ();
27 /* Iterate over data sources */
28 foreach ($matches as $ds) {
29 $ds_raw = array_shift($ds); /* Full string */
30 $ds_name = array_shift($ds);
31 $ds_value = array_shift($ds);
32 $ds_uom = array_shift($ds);
34 /* Parse name, if quoted, strip it down to data source name */
35 if (substr($ds_name, 0, 1) == '\'') {
36 $ds_name = stripcslashes(substr($ds_name, 1, -1));
42 if ($ds_value !== '' && $ds_value !== 'U') {
43 $ds_obj['value'] = (float) $ds_value;
46 $ds_obj['unit'] = $ds_uom;
48 if (isset($ds[0]) && $ds[0] !== '') {
49 $ds_obj['warn'] = $ds[0];
51 if (isset($ds[1]) && $ds[1] !== '') {
52 $ds_obj['crit'] = $ds[1];
54 if (isset($ds[2]) && $ds[2] !== '') {
55 $ds_obj['min'] = (float) $ds[2];
56 } else if ($ds_uom == '%') {
59 if (isset($ds[3]) && $ds[3] !== '') {
60 $ds_obj['max'] = (float) $ds[3];
61 } else if ($ds_uom == '%') {
62 $ds_obj['max'] = 100.0;
65 $perf_data[$ds_name] = $ds_obj;