Exemplo n.º 1
0
 protected function DoExecute()
 {
     echo "<p>Note: You may also want to try the sample SOAP client <a href=\"../webservices/itopsoap.examples.php\">itopsoap.examples.php</a></p>\n";
     $aSOAPMapping = SOAPMapping::GetMapping();
     // this file is generated dynamically with location = here
     $sWsdlUri = 'http' . (utils::IsConnectionSecure() ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . dirname($_SERVER['SCRIPT_NAME']) . '/../webservices/itop.wsdl.php';
     ini_set("soap.wsdl_cache_enabled", "0");
     foreach ($this->m_aTestSpecs as $iPos => $aWebService) {
         echo "<h2>SOAP call #{$iPos} - {$aWebService['verb']}</h2>\n";
         echo "<p>Using WSDL: {$sWsdlUriForService}</p>\n";
         echo "<p>{$aWebService['explain result']}</p>\n";
         $sWsdlUriForService = $sWsdlUri . '?service_category=' . $aWebService['service_category'];
         $this->m_SoapClient = new SoapClient($sWsdlUriForService, array('classmap' => $aSOAPMapping, 'trace' => 1));
         if (false) {
             self::DumpVariable($this->m_SoapClient->__getTypes());
         }
         try {
             $oRes = call_user_func_array(array($this->m_SoapClient, $aWebService['verb']), $aWebService['args']);
         } catch (SoapFault $e) {
             print "<pre>\n";
             print "Request: \n" . htmlspecialchars($this->m_SoapClient->__getLastRequest()) . "\n";
             print "Response: \n" . htmlspecialchars($this->m_SoapClient->__getLastResponse()) . "\n";
             print "</pre>";
             print "Response in HTML: <p>" . $this->m_SoapClient->__getLastResponse() . "</p>";
             throw $e;
         }
         self::DumpVariable($oRes);
         print "<pre>\n";
         print "Request: \n" . htmlspecialchars($this->m_SoapClient->__getLastRequest()) . "\n";
         print "Response: \n" . htmlspecialchars($this->m_SoapClient->__getLastResponse()) . "\n";
         print "</pre>";
         if ($oRes instanceof SOAPResult) {
             $res = $oRes->status;
         } elseif ($oRes instanceof SOAPSimpleResult) {
             $res = $oRes->status;
         } else {
             $res = $oRes;
         }
         if ($res != $aWebService['expected result']) {
             echo "Expecting:<br/>\n";
             var_dump($aWebService['expected result']);
             echo "Obtained:<br/>\n";
             var_dump($res);
             throw new UnitTestException("Expecting result '{$aWebService['expected result']}', but got '{$res}'");
         }
     }
 }
Exemplo n.º 2
0
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Affero General Public License for more details.
//
//   You should have received a copy of the GNU Affero General Public License
//   along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
 * Shows a usage of the SOAP queries 
 *
 * @copyright   Copyright (C) 2010-2012 Combodo SARL
 * @license     http://opensource.org/licenses/AGPL-3.0
 */
require_once 'itopsoaptypes.class.inc.php';
$sItopRoot = 'http' . (utils::IsConnectionSecure() ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . dirname($_SERVER['SCRIPT_NAME']) . '/..';
$sWsdlUri = $sItopRoot . '/webservices/itop.wsdl.php';
//$sWsdlUri .= '?service_category=';
$aSOAPMapping = SOAPMapping::GetMapping();
ini_set("soap.wsdl_cache_enabled", "0");
$oSoapClient = new SoapClient($sWsdlUri, array('trace' => 1, 'classmap' => $aSOAPMapping));
try {
    // The most simple service, returning a string
    //
    $sServerVersion = $oSoapClient->GetVersion();
    echo "<p>GetVersion() returned <em>{$sServerVersion}</em></p>";
    // More complex ones, returning a SOAPResult structure
    // (run the page to know more about the returned data)
    //
    $oRes = $oSoapClient->CreateIncidentTicket('admin', 'admin', 'Email server down', 'HW found shutdown', null, new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', 'Demo'))), new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', 'NW Management'))), new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', 'Troubleshooting'))), '', new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', 'NW support'))), array(new SOAPLinkCreationSpec('Device', array(new SOAPSearchCondition('name', 'switch01')), array()), new SOAPLinkCreationSpec('Server', array(new SOAPSearchCondition('name', 'dbserver1.demo.com')), array())), '1', '1');
    echo "<p>CreateIncidentTicket() returned:\n";
    echo "<pre>\n";
    print_r($oRes);
    echo "</pre>\n";
Exemplo n.º 3
0
function RaiseAlarm($sMessage)
{
    echo "{$sMessage}\n";
    try {
        $sTicketLogin = ReadMandatoryParam('check_ticket_login');
        $sTicketPwd = ReadMandatoryParam('check_ticket_pwd');
        $sTicketTitle = ReadMandatoryParam('check_ticket_title');
        $sTicketCustomer = ReadMandatoryParam('check_ticket_customer');
        $sTicketService = ReadMandatoryParam('check_ticket_service');
        $sTicketSubcategory = ReadMandatoryParam('check_ticket_service_subcategory');
        $sTicketWorkgroup = ReadMandatoryParam('check_ticket_workgroup');
        $sTicketImpactedServer = ReadMandatoryParam('check_ticket_impacted_server');
    } catch (Exception $e) {
        echo "The ticket could not be created: " . $e->GetMessage() . "\n";
        return;
    }
    $sMessage = "Server: [[Server:" . $sTicketImpactedServer . "]]\n" . $sMessage;
    require_once APPROOT . 'webservices/itopsoaptypes.class.inc.php';
    //$sItopRootDefault = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../..';
    //$sItopRoot = utils::ReadParam('check_ticket_itop', $sItopRootDefault);
    $sItopRoot = ReadMandatoryParam('check_ticket_itop');
    $sWsdlUri = $sItopRoot . '/webservices/itop.wsdl.php';
    //$sWsdlUri .= '?service_category=';
    $aSOAPMapping = SOAPMapping::GetMapping();
    ini_set("soap.wsdl_cache_enabled", "0");
    $oSoapClient = new SoapClient($sWsdlUri, array('trace' => 1, 'classmap' => $aSOAPMapping));
    try {
        $oRes = $oSoapClient->CreateIncidentTicket($sTicketLogin, $sTicketPwd, $sTicketTitle, $sMessage, null, new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketCustomer))), new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketService))), new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketSubcategory))), '', new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketWorkgroup))), array(new SOAPLinkCreationSpec('Server', array(new SOAPSearchCondition('name', $sTicketImpactedServer)), array())), '1', '1');
    } catch (Exception $e) {
        echo "The ticket could not be created: SOAP Exception = '" . $e->getMessage() . "'\n";
    }
    //echo "<pre>\n";
    //print_r($oRes);
    //echo "</pre>\n";
    if ($oRes->status) {
        $sTicketName = $oRes->result[0]->values[1]->value;
        echo "Created ticket: {$sTicketName}\n";
    } else {
        echo "ERROR: Failed to create the ticket in target iTop ({$sItopRoot})\n";
        foreach ($oRes->errors->messages as $oMessage) {
            echo $oMessage->text . "\n";
        }
    }
}