| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | class NpcCommentsController extends Controller { |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | function getAck($id) { |
|---|
| 36 | $where = 'c.entry_type = 4'; |
|---|
| 37 | $ack = $this->comments($id, $where); |
|---|
| 38 | return($ack[0]['author_name'] . "*|*" . $ack[0]['comment_data']); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | function getLastComment($id) { |
|---|
| 50 | $where = 'c.entry_type != 4'; |
|---|
| 51 | $comment = $this->comments($id, $where); |
|---|
| 52 | if (isset($comment[0])) { |
|---|
| 53 | return($comment[0]['author_name'] . "*|*" . $comment[0]['comment_data']); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | return(0); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | function getComments() { |
|---|
| 67 | return($this->jsonOutput($this->comments())); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | function getHostComments() { |
|---|
| 78 | $results = $this->flattenArray($this->comments(null, 'o.objecttype_id = 1')); |
|---|
| 79 | return($this->jsonOutput($results)); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | function getServiceComments() { |
|---|
| 90 | $results = $this->flattenArray($this->comments(null, 'o.objecttype_id = 2')); |
|---|
| 91 | return($this->jsonOutput($results)); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | function deleteAllHostComments() { |
|---|
| 102 | |
|---|
| 103 | require_once("plugins/npc/controllers/nagios.php"); |
|---|
| 104 | |
|---|
| 105 | $seen = array(); |
|---|
| 106 | |
|---|
| 107 | $results = $this->flattenArray($this->comments(null, 'o.objecttype_id = 1')); |
|---|
| 108 | |
|---|
| 109 | for ($i = 0; $i < count($results); $i++) { |
|---|
| 110 | $host = $results[$i]['host_name']; |
|---|
| 111 | if (!isset($seen[$host])) { |
|---|
| 112 | $params = array( |
|---|
| 113 | 'command' => 'DEL_ALL_HOST_COMMENTS', |
|---|
| 114 | 'host_name' => $host |
|---|
| 115 | ); |
|---|
| 116 | NpcNagiosController::command($params); |
|---|
| 117 | $seen[$host] = 1; |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | function deleteAllServiceComments() { |
|---|
| 130 | |
|---|
| 131 | require_once("plugins/npc/controllers/nagios.php"); |
|---|
| 132 | |
|---|
| 133 | $seen = array(); |
|---|
| 134 | |
|---|
| 135 | $results = $this->flattenArray($this->comments(null, 'o.objecttype_id = 2')); |
|---|
| 136 | |
|---|
| 137 | for ($i = 0; $i < count($results); $i++) { |
|---|
| 138 | $host = $results[$i]['host_name']; |
|---|
| 139 | $service = $results[$i]['service_description']; |
|---|
| 140 | if (!isset($seen[$host][$service])) { |
|---|
| 141 | $params = array( |
|---|
| 142 | 'command' => 'DEL_ALL_SVC_COMMENTS', |
|---|
| 143 | 'host_name' => $host, |
|---|
| 144 | 'service_description' => $service, |
|---|
| 145 | ); |
|---|
| 146 | NpcNagiosController::command($params); |
|---|
| 147 | $seen[$host][$service] = 1; |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | function comments($id=null, $where='') { |
|---|
| 160 | |
|---|
| 161 | if ($this->id || $id) { |
|---|
| 162 | if ($where != '') { |
|---|
| 163 | $where .= ' AND '; |
|---|
| 164 | } |
|---|
| 165 | $where .= sprintf("c.object_id = %d", is_null($id) ? $this->id : $id); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | $q = new Doctrine_Pager( |
|---|
| 169 | Doctrine_Query::create() |
|---|
| 170 | ->select('i.instance_name,' |
|---|
| 171 | .'o.name1 AS host_name,' |
|---|
| 172 | .'o.name2 AS service_description,' |
|---|
| 173 | .'c.*') |
|---|
| 174 | ->from('NpcComments c') |
|---|
| 175 | ->leftJoin('c.Object o') |
|---|
| 176 | ->leftJoin('c.Instance i') |
|---|
| 177 | ->where("$where") |
|---|
| 178 | ->orderby( 'c.entry_time DESC, c.entry_time_usec DESC' ), |
|---|
| 179 | $this->currentPage, |
|---|
| 180 | $this->limit |
|---|
| 181 | ); |
|---|
| 182 | |
|---|
| 183 | $results = $q->execute(array(), Doctrine::FETCH_ARRAY); |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | $this->numRecords = $q->getNumResults(); |
|---|
| 187 | |
|---|
| 188 | return($results); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | } |
|---|