function test_TestResult_stores_data() { $result = new tx_caretaker_TestResult(123, 1, 1.75, 'This is a Message'); $this->assertEquals($result->getTimestamp(), 123); $this->assertEquals($result->getState(), 1); $this->assertEquals($result->getStateInfo(), 'WARNING'); $this->assertEquals($result->getValue(), 1.75); $this->assertEquals($result->getMessage()->getText(), 'This is a Message'); }
/** * Notify the service about a test status * * @param string $event Event Identifier * @param tx_caretaker_AbstractNode $node * @param tx_caretaker_TestResult $result * @param tx_caretaker_TestResult $lastResult */ public function addNotification($event, $node, $result = NULL, $lastResult = NULL) { // stop if event is not updatedTestResult of a TestNode if ($event != 'updatedTestResult' || is_a($node, 'tx_caretaker_TestNode') == false) { return; } // Check that the result is not equal to the previous one if ($lastResult && $result->getState() == $lastResult->getState()) { return; } // collect the recipients from the node rootline $recipientIds = array(); if (count($this->mail_roles) > 0) { $contacts = array(); foreach ($this->mail_roles as $role) { $contacts = array_merge($contacts, $node->getContacts($role)); } } else { $contacts = $node->getContacts(); } foreach ($contacts as $contact) { $address = $contact->getAddress(); if (!$this->recipients_addresses[$address['uid']]) { $this->recipients_addresses[$address['uid']] = $address; } $recipientIds[] = $address['uid']; } $recipientIds = array_unique($recipientIds); // store the notifications for the recipients foreach ($recipientIds as $recipientId) { if (!isset($this->recipients_messages[$recipientId])) { $this->recipients_messages[$recipientId] = array('messages' => array(), 'num_undefined' => 0, 'num_ok' => 0, 'num_warning' => 0, 'num_error' => 0, 'num_ack' => 0, 'num_due' => 0); } switch ($result->getState()) { case tx_caretaker_Constants::state_undefined: $this->recipients_messages[$recipientId]['num_undefined']++; break; case tx_caretaker_Constants::state_ok: $this->recipients_messages[$recipientId]['num_ok']++; break; case tx_caretaker_Constants::state_warning: $this->recipients_messages[$recipientId]['num_warning']++; break; case tx_caretaker_Constants::state_error: $this->recipients_messages[$recipientId]['num_error']++; break; case tx_caretaker_Constants::state_ack: $this->recipients_messages[$recipientId]['num_ack']++; break; case tx_caretaker_Constants::state_due: $this->recipients_messages[$recipientId]['num_due']++; break; } array_unshift($this->recipients_messages[$recipientId]['messages'], '*' . ($lastResult ? $lastResult->getLocallizedStateInfo() . '->' : '') . $result->getLocallizedStateInfo() . ' ' . $node->getInstance()->getTitle() . ':' . $node->getTitle() . '* ' . $node->getCaretakerNodeId() . chr(10) . chr(10) . $result->getLocallizedInfotext() . chr(10) . str_replace('###', $node->getCaretakerNodeId(), $this->mail_link) . chr(10)); } }
/** * Save the Testresult for the given TestNode * @param tx_caretaker_TestNode $test * @param tx_caretaker_TestResult $testResult */ function saveTestResultForNode(tx_caretaker_TestNode $test, $testResult) { $values = array('test_uid' => $test->getUid(), 'instance_uid' => $test->getInstance()->getUid(), 'tstamp' => $testResult->getTimestamp(), 'result_status' => $testResult->getState(), 'result_value' => $testResult->getValue(), 'result_msg' => $testResult->getMessage()->getText(), 'result_values' => serialize($testResult->getMessage()->getValues()), 'result_submessages' => serialize($testResult->getSubMessages())); // store log of results $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_caretaker_testresult', $values); // store last results for fast access $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_caretaker_lasttestresult', 'test_uid = ' . $test->getUid() . ' AND instance_uid = ' . $test->getInstance()->getUid(), '', '', 1); if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_caretaker_lasttestresult', 'uid = ' . $row['uid'], $values); } else { $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_caretaker_lasttestresult', $values); } }