| 45 | | function get_targets() { |
|---|
| 46 | | $sth = $this->db->prepare("select distinct(target) as target from stratcon.loading_dock_check_s"); |
|---|
| 47 | | $sth->execute(); |
|---|
| | 46 | function get_noits() { |
|---|
| | 47 | $sth = $this->db->prepare(" |
|---|
| | 48 | select distinct(remote_address) as remote_address |
|---|
| | 49 | from stratcon.loading_dock_check_s |
|---|
| | 50 | join ( select id, max(whence) as whence |
|---|
| | 51 | from stratcon.loading_dock_check_s |
|---|
| | 52 | group by id) latestrecord |
|---|
| | 53 | USING (id,whence)"); |
|---|
| | 54 | $rv = array(); |
|---|
| | 55 | while($row = $sth->fetch()) { |
|---|
| | 56 | $rv[] = $row['remote_address']; |
|---|
| | 57 | } |
|---|
| | 58 | return $rv; |
|---|
| | 59 | } |
|---|
| | 60 | function valid_source_variables() { |
|---|
| | 61 | return array('module', 'remote_address', 'target', 'name', 'metric_name'); |
|---|
| | 62 | } |
|---|
| | 63 | function get_sources($want, $fixate, $active = true) { |
|---|
| | 64 | $vars = $this->valid_source_variables(); |
|---|
| | 65 | if(!in_array($want, $vars)) return array(); |
|---|
| | 66 | $binds = array(); |
|---|
| | 67 | $named_binds = array(); |
|---|
| | 68 | $where_sql = ''; |
|---|
| | 69 | foreach($vars as $var) { |
|---|
| | 70 | if(isset($fixate[$var])) { |
|---|
| | 71 | $where_sql .= " and $var = ?"; |
|---|
| | 72 | $binds[] = $fixate[$var]; |
|---|
| | 73 | $named_binds[$var] = $fixate[$var]; |
|---|
| | 74 | } |
|---|
| | 75 | } |
|---|
| | 76 | $sql = " |
|---|
| | 77 | select $want, min(sid) as sid, min(metric_type) as metric_type, count(1) as cnt |
|---|
| | 78 | from stratcon.mv_loading_dock_check_s c |
|---|
| | 79 | join stratcon.metric_name_summary m using (sid) |
|---|
| | 80 | where active = " . ($active ? "true" : "false") . $where_sql . " |
|---|
| | 81 | group by $want |
|---|
| | 82 | order by $want"; |
|---|
| | 83 | $sth = $this->db->prepare($sql); |
|---|
| | 84 | $sth->execute($binds); |
|---|
| | 85 | $rv = array(); |
|---|
| | 86 | while($row = $sth->fetch()) { |
|---|
| | 87 | $copy = $named_binds; |
|---|
| | 88 | $copy[$want] = $row[$want]; |
|---|
| | 89 | $copy['sid'] = $row['sid']; |
|---|
| | 90 | $copy['id'] = 'ds'; |
|---|
| | 91 | foreach($vars as $var) { |
|---|
| | 92 | $copy['id'] .= "-" . $copy[$var]; |
|---|
| | 93 | } |
|---|
| | 94 | $copy['cnt'] = $row['cnt']; |
|---|
| | 95 | if($copy['cnt'] == 1) |
|---|
| | 96 | $copy['metric_type'] = $row['metric_type']; |
|---|
| | 97 | $rv[] = $copy; |
|---|
| | 98 | } |
|---|
| | 99 | return $rv; |
|---|
| | 100 | } |
|---|
| | 101 | function get_targets($remote_address = null) { |
|---|
| | 102 | if($remote_address) { |
|---|
| | 103 | $sth = $this->db->prepare("select distinct(target) as target from stratcon.loading_dock_check_s where remote_address = ?"); |
|---|
| | 104 | $sth->execute(array($remote_address)); |
|---|
| | 105 | } |
|---|
| | 106 | else { |
|---|
| | 107 | $sth = $this->db->prepare("select distinct(target) as target from stratcon.loading_dock_check_s"); |
|---|
| | 108 | $sth->execute(); |
|---|
| | 109 | } |
|---|