/** * Create a new transmission message (XMWS XML request) * @param \Ballen\Senitor\Entities\Target $target * @param string $endpoint The endpoint action/request. * @param \Ballen\Senitor\Entities\MessageBag $request */ public function __construct(Target $target, $module, $endpoint, MessageBag $request) { if (empty($request)) { throw new \Ballen\Senitor\Exceptions\InvalidXmwsEndpoint("The XMWS endpoint cannot be empty."); } $this->target = $target; $this->module = $module; $this->endpoint = $endpoint; $this->content = $request->getXml(); $this->transmission = $this->buildXml($target, $request); }
/** * Set request data to be sent with the XMWS request. * @param MessageBag $data * @return Senitor * @throws InvalidArgumentException */ public function setRequestData($data = null) { if ($data instanceof MessageBag) { $this->data = $data; } if (is_array($data)) { $this->data = MessageBag::getInstance(); $this->data->setItems($data); } return $this; }
function sendSenitorRequest($params, $module, $endpoint, $array_data = array()) { global $xmws; global $default_modules; $serveraccesshash = explode(",", $params["serveraccesshash"]); $server_apikey = $serveraccesshash[1]; # Get the API Key $resp = null; if ($xmws == null) { $xmws = SenitorFactory::create(getAddress($params), $server_apikey, $params["serverusername"], $params["serverpassword"], array('verify' => false)); } try { // Workaround for an exception caused by having multiple Senitor requests per PHP page. MessageBag::getInstance()->reset(); } catch (Exception $e) { } $replacevars = array("serveraccesshash", "serverusername", "serverpassword", "password"); $use_default_modules = $params["configoption3"] === "on" || $params["configoption3"] === "yes"; if ($use_default_modules && !empty($default_modules[$module . "." . $endpoint])) { $module = $default_modules[$module . "." . $endpoint]; } try { $xmws->setModule($module); $xmws->setEndpoint($endpoint); $xmws->SetRequestData($array_data); $resp = $xmws->send(); } catch (Exception $e) { $str_error = "Caught exception: " . $e->getMessage() . "\n\n" . $e->getTraceAsString() . "\n"; logModuleCall("Sentora", $module . "." . $endpoint, $array_data, $str_error, "", $replacevars); return null; } logModuleCall("Sentora", $module . "." . $endpoint, $array_data, $resp->asArray(), "", $replacevars); return $resp; }