Example #1
0
 public function testListInNamespace()
 {
     $service = $this->loginToRealService();
     $entities = $service->getSavedSearches()->items(array('namespace' => Splunk_Namespace::createSystem()));
     $this->assertCount(0, $entities, 'Expected no saved searches in the system namespace.');
     return $entities;
 }
 public function testDispatchInNamespace()
 {
     $service = $this->loginToRealService();
     // Setup
     $savedSearchName = $this->createTempName();
     $savedSearch = $service->getSavedSearches()->create($savedSearchName, array('namespace' => Splunk_Namespace::createApp('launcher'), 'search' => 'index=_internal | head 1'));
     // Test
     $job = $savedSearch->dispatch();
     // Teardown
     $savedSearch->delete();
 }
Example #3
0
 /**
  * Constructs a new context with the specified parameters.
  *
  * @param array $args {<br/>
  *      **username**: (optional) The username to login with. Defaults to 
  *                    "admin".<br/>
  *      **password**: (optional) The password to login with. Defaults to 
  *                    "changeme".<br/>
  *      **token**: (optional) The authentication token to use. If provided,
  *                 the username and password are ignored and there is no
  *                 need to call login(). In the format "Splunk SESSION_KEY".
  *                 <br/>
  *      **host**: (optional) The hostname of the Splunk server. Defaults to 
  *                "localhost".<br/>
  *      **port**: (optional) The port of the Splunk server. Defaults to 
  *                8089.<br/>
  *      **scheme**: (optional) The scheme to use: either "http" or "https". 
  *                  Defaults to "https".<br/>
  *      **namespace**: (optional) Namespace that all object lookups will 
  *                     occur in by default. Defaults to 
  *                     `Splunk_Namespace::createDefault()`.<br/>
  *      **http**: (optional) An Http object that will be used for 
  *                performing HTTP requests. This is intended for testing 
  *                only.<br/>
  * }
  */
 public function __construct($args = array())
 {
     $args = array_merge(array('username' => 'admin', 'password' => 'changeme', 'token' => NULL, 'host' => 'localhost', 'port' => 8089, 'scheme' => 'https', 'namespace' => Splunk_Namespace::createDefault(), 'http' => new Splunk_Http()), $args);
     $this->username = $args['username'];
     $this->password = $args['password'];
     $this->token = $args['token'];
     $this->host = $args['host'];
     $this->port = $args['port'];
     $this->scheme = $args['scheme'];
     $this->namespace = $args['namespace'];
     $this->http = $args['http'];
 }
Example #4
0
 public function testGetNamespaceOfWildcardedReference()
 {
     $service = $this->loginToRealService();
     $requestNamespace = Splunk_Namespace::createUser(NULL, NULL);
     $this->assertFalse($requestNamespace->isExact());
     $index = $service->getIndexes()->getReference("_internal", $requestNamespace);
     $actualNamespace = $index->getNamespace();
     $this->assertTrue($actualNamespace !== NULL);
     $this->assertTrue($actualNamespace !== $requestNamespace);
     $this->assertTrue($actualNamespace->isExact());
 }
Example #5
0
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Jobs | Splunk SDK for PHP Examples</title>
  <link rel="stylesheet" type="text/css" href="shared/style.css" />
</head>
<body>
<?php 
require 'shared/navbar.php';
?>

<h2>Jobs</h2>
<?php 
$service = new Splunk_Service($SplunkExamples_connectArguments);
// (NOTE: Can throw HTTP 401 if bad credentials)
$service->login();
// Get all jobs
$jobs = $service->getJobs()->items(array('namespace' => Splunk_Namespace::createUser(NULL, NULL)));
?>

<table class="table table-bordered table-striped">
  <thead>
    <tr>
      <th>Search Expression</th>
      <th>Owner</th>
      <th>App</th>
      <th>Status</th>
      <th>Actions</th>
    </tr>
  </thead>
  <?php 
foreach ($jobs as $job) {
    echo '<tr><td>';
Example #6
0
 /**
  * Creates a non-wildcarded namespace with the specified properties.
  * 
  * @param string $owner         name of a Splunk user (ex: "admin").
  * @param string $app           name of a Splunk app (ex: "search").
  * @param string $sharing       one of {'user', 'app', 'global', 'system'}.
  * @see user()
  */
 public static function createExact($owner, $app, $sharing)
 {
     $numArgs = func_num_args();
     // must be own line for PHP < 5.3.0
     Splunk_Namespace::ensureArgumentCountEquals(3, $numArgs);
     if (!in_array($sharing, array('user', 'app', 'global', 'system'))) {
         throw new InvalidArgumentException('Invalid sharing.');
     }
     if ($owner === NULL || $owner === '' || $owner === '-') {
         throw new InvalidArgumentException('Invalid owner.');
     }
     if ($app === NULL || $app === '' || $app === '-') {
         throw new InvalidArgumentException('Invalid app.');
     }
     return new Splunk_Namespace($owner, $app, $sharing);
 }
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Saved Searches | Splunk SDK for PHP Examples</title>
  <link rel="stylesheet" type="text/css" href="shared/style.css" />
</head>
<body>
<?php 
require 'shared/navbar.php';
?>

<h2>Saved Searches</h2>
<?php 
$service = new Splunk_Service($SplunkExamples_connectArguments);
// (NOTE: Can throw HTTP 401 if bad credentials)
$service->login();
// Get all saved searches
$savedSearches = $service->getSavedSearches()->items(array('namespace' => Splunk_Namespace::createUser(NULL, NULL)));
?>

<table class="table table-bordered table-striped">
  <thead>
    <tr>
      <th>Name</th>
      <th>Actions</th>
    </tr>
  </thead>
  <?php 
foreach ($savedSearches as $savedSearch) {
    echo '<tr><td>';
    echo htmlspecialchars($savedSearch->getName());
    echo '</td><td>';
    echo '<a href="saved_search.php?action=run&id=' . urlencode($savedSearch->getName()) . '">Run</a>';
Example #8
0
 /**
  * Gets the non-wildcarded namespace in which this entity resides.
  *
  * @return Splunk_Namespace     The non-wildcarded namespace in which this
  *                              entity resides.
  */
 public function getNamespace()
 {
     // If this is an entity reference with an exact namespace, return it.
     if (!$this->loaded) {
         $effectiveNamespace = $this->namespace;
         if ($effectiveNamespace === NULL) {
             $effectiveNamespace = $this->service->getNamespace();
         }
         if ($effectiveNamespace->isExact()) {
             return $effectiveNamespace;
         }
     }
     // Extract the namespace from this entity's content.
     $acl = $this['eai:acl'];
     return Splunk_Namespace::createExact($acl['owner'], $acl['app'], $acl['sharing']);
 }
Example #9
0
 public function testControlInCustomNamespace()
 {
     $service = $this->loginToRealService();
     // Setup
     $job = $service->getJobs()->create('search index=_internal | head 1', array('namespace' => Splunk_Namespace::createUser('admin', 'launcher')));
     // Test & Teardown
     // (Ensure this doesn't throw HTTP 404)
     $job->cancel();
 }
Example #10
0
<?php

require_once '../Splunk.php';
require_once 'settings.php';
$method = $_SERVER['REQUEST_METHOD'];
$action = array_key_exists('action', $_REQUEST) ? $_REQUEST['action'] : 'help';
$id = array_key_exists('id', $_REQUEST) ? $_REQUEST['id'] : '';
$service = new Splunk_Service($SplunkExamples_connectArguments);
// (NOTE: Can throw HTTP 401 if bad credentials)
$service->login();
if ($id !== '') {
    $savedSearch = $service->getSavedSearches()->get($id, Splunk_Namespace::createUser(NULL, NULL));
}
if ($method === 'POST') {
    $search = $_POST['search'];
    if ($action === 'create') {
        $name = $_POST['name'];
        $service->getSavedSearches()->create($name, array('search' => $search));
        header('Location: list_saved_searches.php');
        exit;
    } else {
        if ($action === 'edit') {
            $savedSearch->update(array('search' => $search));
            header('Location: list_saved_searches.php');
            exit;
        } else {
            die('Unrecognized action.');
        }
    }
} else {
    if ($method === 'GET') {
Example #11
0
<?php

require_once '../Splunk.php';
require_once 'settings.php';
$method = $_SERVER['REQUEST_METHOD'];
$action = array_key_exists('action', $_REQUEST) ? $_REQUEST['action'] : 'help';
$id = array_key_exists('id', $_REQUEST) ? $_REQUEST['id'] : '';
$service = new Splunk_Service($SplunkExamples_connectArguments);
// (NOTE: Can throw HTTP 401 if bad credentials)
$service->login();
if ($id !== '') {
    $job = $service->getJobs()->get($id, Splunk_Namespace::createUser(NULL, NULL));
}
if ($method === 'GET') {
    if ($action === 'help') {
        header('Location: list_jobs.php');
        exit;
    } else {
        if ($action === 'view') {
            // (continue)
        } else {
            if ($action === 'pause') {
                $job->pause();
                header('Location: list_jobs.php');
                exit;
            } else {
                if ($action === 'unpause') {
                    $job->unpause();
                    header('Location: list_jobs.php');
                    exit;
                } else {
Example #12
0
 /**
  * @expectedException PHPUnit_Framework_Error
  */
 public function testCreateExactWithTooFewArguments()
 {
     Splunk_Namespace::createExact('theapp', 'theowner');
 }