Пример #1
0
  <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>';
Пример #2
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') {