This is the code my predecessor created, it was only in the production server and had to ask someone to copy it for me so I can put it in the pre-production server. In case your wondering why am I testing, debugging, resolving in the pre-prod server. The development server is inaccessible even before I got here. I have been asking for the access to it until now nothing.
I have changed some of the values like the ip address, password. Tried it and it does create a ticket only it times out in thanks.php. (Also copied thanks.php into the pre-prod). I tried ACL, GenericAgent just as to have minimal change. If I am going to add a code here to add dynamic field to be set I need to change atleast is TicketCreate right?
Code: Select all
class TicketCreate {
/**
* The ticket create action is ticketCreate.
*
* @var CONST
*/
CONST TICKET_ACTION = 'ticketCreate';
/**
* The ticket create username for webserivce.
*
* @var CONST
*/
CONST USER_NAME = 'otrsdeveloper';
/**
* The ticket create password for webservice.
*
* @var CONST
*/
CONST PASSWORD = '#############';
/**
* The ticket title.
*
* @var string
*/
public static $ticket_title = NULL;
/**
* The ticket create subject name.
*
* @var string
*/
public static $ticket_subject = NULL;
/**
* The t:icket create description name.
*
* @var string
*/
public static $ticket_description = NULL;
/**
* The ticket create body type.
*
* @var string
*/
public static $body = NULL;
/**
* The ticket create customer user name.
*
* @var CONST
*/
CONST CUSTOMER_USER = 'nagios';
/**
* The ticket create queue id.
*
* @var CONST
*/
CONST QUEUE_ID = 84;
/**
* The ticket create state id.
*
* @var CONST
*/
CONST STATE_ID = 1;
/**
* The ticket create priority id.
*
* @var CONST
*/
CONST PRIORITY_ID = 3;
/**
* The ticket create type id.
*
* @var CONST
*/
CONST TYPE_ID = 2;
/**
* The ticket responsible id.
*
* @var CONST
*/
CONST RESPONSIBLE_ID = 229;
/**
* The ticket SLAID.
*
* @var CONST
*/
CONST SLAID = 9;
/**
* The ticket service id.
*
* @var CONST
*/
CONST SERVICE_ID = 40;
/**
* The ticket create body content type.
*
* @var CONST
*/
CONST CONTENT_TYPE = 'text/html; charset="iso-8859-15"';
/**
* The ticket create webservice URL.
*
* @var CONST
*/
CONST WEBSERVICE_URL = 'https://xxx.xxx.xxx.xxx/otrs/nph-genericinterface.pl/Webservice/WebServices';
/**
* __Construct
*
* @var string $ticket_title, $ticket_subject
*
* @access public
* @return void
*/
function __construct() {
$this->ticket_title = $ticket_title;
$this->ticket_subject = $ticket_subject;
}
/**
* soapClient
*
* @var int $webservice_url
* @access public
* @return soap client
*/
public function soapClient(){
try
{
// make sure it's the same as the namespace in network config of the webservice
$client = new SoapClient(NULL,
array('location' => self::WEBSERVICE_URL,
'uri' => 'Core',
'trace' => true,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED));
}
catch (Exception $e)
{
return $e->getMessage();
}
return $client;
}
/**
* ticketCreateAction
*
* @var int $client,$ticket_id
* @access public
* @return ticket_id
*/
public function ticketCreateAction(){
$host = trim($_REQUEST['host']);
$service_status = trim($_REQUEST['service_status']);
$service_infromation = trim($_REQUEST['service_infromation']);
// Define the status name by int vlaue
if($service_status == 0) $service_status = 'OK';
if($service_status == 1) $service_status = 'WARNING';
if($service_status == 2) $service_status = 'CRITICAL';
if($service_status == 3) $service_status = 'UNKNOWN';
$this->ticket_title = 'NagiosYES4G - '.$service_infromation.' -'.$host;
//$this->ticket_title = 'NagiosYES4G - Test Ticket - Please kindly ignore - OTRS Team';
$this->ticket_subject = $this->ticket_title;
$this->ticket_description = $this->ticketDescriptionTable($host,$service_status,$service_infromation);
// call otrs soap client
$client = $this->soapClient();
$ticket_id = $client->__soapCall(self::TICKET_ACTION, array(
new SoapParam(self::USER_NAME, "UserLogin"),
new SoapParam(self::PASSWORD, "Password"),
new SoapParam(array(
"Title" => $this->ticket_title,
"CustomerUser" => self::CUSTOMER_USER,
"QueueID" => self::QUEUE_ID,
"StateID" => self::STATE_ID,
"PriorityID" => self::PRIORITY_ID,
"TypeID" => self::TYPE_ID,
"ResponsibleID" => self::RESPONSIBLE_ID, // mon.otrs
"SLAID" => self::SLAID, // Sev 3
"ServiceID" => self::SERVICE_ID,
), "Ticket"),
new SoapParam(array(
"Subject" => $this->ticket_subject,
"Body" => $this->ticket_description,
"ContentType" => self::CONTENT_TYPE,
), "Article"),
// Set Value for the Particular DynamicFields
new SoapParam(array("Name" => "Severity", "Value" => 'Severity 3'), "DynamicField") ,
new SoapParam(array("Name" => "Category1", "Value" => 'Server'), "DynamicField") ,
new SoapParam(array("Name" => "subCat", "Value" => 'Others'), "DynamicField") ,
));
return $ticket_id;
}
/**
* ticketDescriptionTable
*
* @var string $host, $service_status, $service_infromation
* $service_duration, $last_check_time, $next_scheduled_check
* $host, $service_status, $service_infromation,
* $last_check_time, $next_scheduled_check
*
* @access public
* @return table
*/
public function ticketDescriptionTable($host,$service_status,$service_infromation){
// Request from Thruk
$service_duration = trim($_REQUEST['service_duration']);
$service_infromation = trim($_REQUEST['service_infromation']);
$last_check_time = trim($_REQUEST['last_check_time']);
$next_scheduled_check = trim($_REQUEST['next_scheduled_check']);
$description = "***** NagiosYES4G Service Monitor XI Alert *****<br>";
$description .= "Status: ".$service_status."<br>";
$description .= "Service : ".$service_infromation." <br>";
$description .= "Host: ".$host."<br>";
$description .= "Service Duration: ".$service_duration."<br>";
$description .= "Last Check: ".$last_check_time."<br>";
$description .= "Next Check: ".$next_scheduled_check."<br>";
return $description;
}
}
// Create object for ticket create
$ticket = new TicketCreate();
// call ticket create action
$ticket_id = $ticket->ticketCreateAction();
if($ticket_id['TicketNumber'] != "")
{
$tn = $ticket_id['TicketNumber'];
$tid = $ticket_id['TicketID'];
header("location:https://xxxxxxx.xxxxxxxx.xxxxxx/nagios/thanks.php?tn=$tn&tid=$tid");
}
?>