first let me apologize, I'm a Network engineer and not a coder... so please if you will bear with me here.
Here's what I'm up against and I can't for the life of me find an elegant way to do it.
I'm using nagios (sure many of you are familiar with it) and am getting performance data from the service checks. This one in particular returns values like: module 2 inlet temperature module 2 outlet temperature module 2 asic-4 temperature module 3 inlet temperature module 3 outlet temperature module 4 inlet temperature module 4 outlet temperature ... and so on These values are all presented in a single array. What I'm trying to do is: match the first 2 words/values in the string in order to create "groups" of array key values to be used to generate RRD graphs with... the RRD part I don't need any help with, but the matching and output I do.
I should also note that there may be different array values in here as well depending on the device the data is coming from (i.e. it might show up as "Switch #1 Sensor #1 Temperature") and while I'm not worried about that for the moment, I will be using this script to evaluate those values in the future to create their own respective graphs.
So, down to business, my thought was to create two arrays from the original: use preg_match initially to look for /.outlet.|.asic./ as these are "hot" temps, then further refine by breaking that new array down to either just the second value (int) or first two values (module #) for later comparison
use preg_match secondly to look for /.inlet./ as these are "cold" temps, then further refine by breaking that new array down same as the former.
Should now have two arrays with either key=># or key=>module # then use array_intersect to look for matches across the two arrays and output the keys so I can use them to generate the graphs.
Does that make sense? In other words, I only want matching module # entries to be selected to use in my graphing. i.e. module 2 inlet, module 2 outlet, module 2 asic... then repeat for - module 3 inlet, module 3 outlet, etc...
This is what I've tried and it hasn't worked the way I wanted at all:
$test = array("module 1 inlet temperature", "module 2 inlet temperature", "module 2 asic-4 temperature", "module 2 outlet temperature", "module 1 outlet temperature");
$results = array();
foreach($test as $key => $value) {
preg_match("/.*inlet.*|.*asic.*/", $test[$key]);
preg_match("/module [0-9]?[0-9]/", $test[$key]);
$results[] = $value;
}
if(preg_match("/.*outlet.*/", $test[$key]));
foreach($test as $key1 => $value1) {
preg_match("/module [0-9]?[0-9]/", $test[$key1]);
$results1[] = $value1;
}#
}
$results3 = array_intersect($results, $results1)
Any help here would be really appreciated. I'm sure my explanation here was pretty confusing so hope someone takes pity on me and gives a guy a hand...
Thanks in advance.