Changeset 7642
- Timestamp:
- Apr 1, 2010, 8:26:53 AM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/inc/KMLFile.class.php
r7640 r7642 93 93 } 94 94 95 /* 96 * Function: getPlacemarkByName 97 * Parameters: string $name 98 * Function: Find the first KMLPlacemark with the name $name and return its position. If not found, return false 99 */ 100 public function getPlacemarkByName($name) { 101 $nodesCount = count($this->KMLPlacemarks); 102 for ($i = 0; $i < $nodesCount; $i++) { 103 if ($this->KMLPlacemarks[$i]->getName() == $name) { 104 return $i; 105 } 106 } 107 return false; 108 } 109 110 /* 111 * Function: parseLocationFile 112 * Parameters: string $file 113 * Function: Parse the node location file updating or adding KMLPlacemark objects to the current KMLFile object 114 */ 95 115 public function parseLocationFile($file) { 96 //preg_match_all('#\[(^\/.+?)\]#is', $file, $matches);97 116 $nodesCount = preg_match_all('/\[[a-zA-Z0-9]*\]/i', $file, $nodes, PREG_OFFSET_CAPTURE); 98 117 for ($i = 0; $i < $nodesCount; $i++) { 118 // TODO: Needs checking for parsing errors 99 119 $location = $this->findInLocationFile($file, 'location', $nodes[0][$i][1]); 100 120 $status = $this->findInLocationFile($file, 'status', $nodes[0][$i][1]); … … 106 126 $name = $this->findInLocationFile($file, 'name', $nodes[0][$i][1]); 107 127 108 $placemark = new KMLPlacemark(); 109 $placemark->setName($name); 110 $placemark->setDescription('Naam: ' . $name . '<br/>Locatie: ' . $location . '<br/>Status: ' . $status . '<br/>Latitude: ' . $latitude . '<br/>Longitude: ' . $longitude . '<br/>Interfaces: ' . $interfaces . '<br/>Master IP: ' . $masterip . '<br/>Node type: ' . $nodetype); 111 $placemark->setLongitude($longitude); 112 $placemark->setLatitude($latitude); 113 $placemark->setStyle($status == 'up' ? 'greenArrowIcon' : 'redArrowIcon'); 114 $this->addPlacemark($placemark); 115 } 116 } 117 128 $descriptionLocation = 'Naam: ' . $name . '<br/>Locatie: ' . $location . '<br/>Status: ' . $status . '<br/>Latitude: ' . $latitude . '<br/>Longitude: ' . $longitude . '<br/>Interfaces: ' . $interfaces . '<br/>Master IP: ' . $masterip . '<br/>Node type: ' . $nodetype . '<br/><br/>'; 129 130 if ($placemarkPosition = $this->getPlacemarkByName($name)) { 131 $this->KMLPlacemarks[$placemarkPosition]->setDescriptionLocation($descriptionLocation); 132 $this->KMLPlacemarks[$placemarkPosition]->setLongitude($longitude); 133 $this->KMLPlacemarks[$placemarkPosition]->setLatitude($latitude); 134 } else { 135 $placemark = new KMLPlacemark(); 136 $placemark->setName($name); 137 $placemark->setDescriptionLocation($descriptionLocation); 138 $placemark->setLongitude($longitude); 139 $placemark->setLatitude($latitude); 140 $this->addPlacemark($placemark); 141 } 142 } 143 } 144 145 /* 146 * Function: findInLocationFile 147 * Parameters: string $file, string $keyword, integer $offset 148 * Function: Find the $keyword in $file and return the value of $keyword, starting at $offset, on error return false 149 */ 118 150 private function findInLocationFile($file, $keyword, $offset) { 119 $start 151 $start = strpos($file, $keyword, $offset) + strlen($keyword . ' = '); 120 152 $end = strpos($file, "\n", $start); 121 return substr($file, $start, $end - $start); 122 } 123 153 154 if ($start && $end && ($start < $end)) { 155 return substr($file, $start, $end - $start); 156 } else { 157 return false; 158 } 159 } 160 161 /* 162 * Function: parseStatusFile 163 * Parameters: string $file 164 * Function: Parse the node status file updating or adding KMLPlacemark objects to the current KMLFile object 165 */ 124 166 public function parseStatusFile($file) { 125 /*126 * TODO: Needs to be rebuild so it doesn't create a new KMLFile object,127 * but add the KMLPlacemarks to the current object.128 */129 167 $fileContents = explode("\r\n", $file); 130 168 … … 133 171 } 134 172 135 $lines = count($fileContents);136 for ($i = 1; $i < count($lines); $i++) {173 $linesCount = count($fileContents); 174 for ($i = 1; $i < $linesCount - 1; $i++) { 137 175 $lineContent = explode(',', $fileContents[$i]); 138 176 … … 141 179 } 142 180 143 // TODO: Process all lines and create KMLPlacemark objects we can add to a new KMLFile object 181 // TODO: Process all lines and update KMLPlacemark objects we already have in the current object 182 $type = $lineContent[0]; 183 $host_name = str_replace('CNode', '', $lineContent[1]); 184 $has_been_checked = $lineContent[2]; 185 $check_execution_time = $lineContent[3]; 186 $current_state = $lineContent[4]; 187 $last_hard_state = $lineContent[5]; 188 $last_check = $lineContent[6]; 189 $problem_has_been_acknowledged = $lineContent[7]; 190 191 $descriptionStatus = 'Type: ' . $type . '<br/>Host name: ' . $host_name . '<br/>Has been checked: ' . $has_been_checked . '<br/>Check execution time: ' . $check_execution_time . '<br/>Currenr state: ' . $current_state . '<br/>Last hard state: ' . $last_hard_state . '<br/>Last check: ' . $last_check . '<br/>Problem has been acknowledged: ' . $problem_has_been_acknowledged . '<br/><br/>'; 192 193 if ($placemarkPosition = $this->getPlacemarkByName($host_name)) { 194 $this->KMLPlacemarks[$placemarkPosition]->setDescriptionStatus($descriptionStatus); 195 } else { 196 $placemark = new KMLPlacemark(); 197 $placemark->setName($host_name); 198 $placemark->setDescriptionStatus($descriptionStatus); 199 $this->addPlacemark($placemark); 200 } 144 201 } 145 202 } -
trunk/src/inc/KMLPlacemark.class.php
r7637 r7642 27 27 </Placemark>'; 28 28 29 private $name; 30 private $description; 31 private $longitude; 32 private $latitude; 33 private $style; 29 private $name; // Name of the node 30 private $descriptionLocation; // Location information of the node 31 private $descriptionStatus; // Status information of the node 32 private $longitude; // Longitude of the node 33 private $latitude; // Latitude of the node 34 private $style; // Style of the placemark 34 35 35 36 /* … … 39 40 */ 40 41 function __construct() { 42 $this->name = ''; 43 $this->descriptionLocation = ''; 44 $this->descriptionStatus = ''; 45 $this->longitude = 0; 46 $this->latitude = 0; 47 $this->style = 'orangeArrowIcon'; 41 48 } 42 49 … … 45 52 } 46 53 47 function setDescription($newDescription) { 48 $this->description = (string) $newDescription; 54 function getName() { 55 return $this->name; 56 } 57 58 function setDescriptionLocation($newDescriptionLocation) { 59 $this->descriptionLocation = (string) $newDescriptionLocation; 60 } 61 62 function setDescriptionStatus($newDescriptionStatus) { 63 $this->descriptionStatus = (string) $newDescriptionStatus; 49 64 } 50 65 … … 65 80 66 81 $toString = str_replace('%NAME%', $this->name, $toString); 67 $toString = str_replace('%DESCRIPTION%', $this->description , $toString);82 $toString = str_replace('%DESCRIPTION%', $this->descriptionLocation . $this->descriptionStatus, $toString); 68 83 $toString = str_replace('%LONGITUDE%', $this->longitude, $toString); 69 84 $toString = str_replace('%LATITUDE%', $this->latitude, $toString); -
trunk/src/index.php
r7640 r7642 12 12 $kmlPlacemark1 = new KMLPlacemark(); 13 13 $kmlPlacemark1->setName('Test name'); 14 $kmlPlacemark1->setDescription('Test description'); 14 $kmlPlacemark1->setDescriptionLocation('Test location description'); 15 $kmlPlacemark1->setDescriptionStatus('Test status description'); 15 16 $kmlPlacemark1->setLatitude(52.138476); 16 17 $kmlPlacemark1->setLongitude(4.463046); … … 20 21 $kmlPlacemark2 = new KMLPlacemark(); 21 22 $kmlPlacemark2->setName('Placemark 2 name'); 22 $kmlPlacemark2->setDescription('This is the second placemark description'); 23 $kmlPlacemark2->setDescriptionLocation('This is the second placemark location description'); 24 $kmlPlacemark2->setDescriptionStatus('This is the second placemark status description'); 23 25 $kmlPlacemark2->setLatitude(52.638476); 24 26 $kmlPlacemark2->setLongitude(4.063046); … … 31 33 echo $kml->toString(); 32 34 35 echo "\r\n\r\n\r\n\r\n\r\n -------------------------------------------------- \r\n\r\n\r\n\r\n\r\n"; 36 33 37 // Now let's try reading from files and parsing the data in the files. 34 38 // First off, we create a new KMLFile object … … 40 44 echo $kmlFile->toString(); 41 45 46 echo "\r\n\r\n\r\n\r\n\r\n -------------------------------------------------- \r\n\r\n\r\n\r\n\r\n"; 47 42 48 // Let's try to read the node status file 43 49 $nodeStatus = new FileHandler($config['node_status_file']); 44 50 $kmlFile->parseStatusFile($nodeStatus->getFile()); 51 echo $kmlFile->toString(); 45 52 /* 46 53 * TODO: Needs better parsing of the file now we have two seperate
Note:
See TracChangeset
for help on using the changeset viewer.