Package com.splunk

Examples of com.splunk.Service


        if (command.args.length != 1)
            Command.error("Search expression required");
        String query = command.args[0];

        Service service = Service.connect(command.opts);

        // Check the syntax of the query.
        try {
            Args parseArgs = new Args("parse_only", true);
            service.parse(query, parseArgs);
        }
        catch (HttpException e) {
            String detail = e.getDetail();
            Command.error("query '%s' is invalid: %s", query, detail);
        }

        // This is the simplest form of searching splunk. Note that additional
        // arguments are allowed, but they are not shown in this example.
        InputStream stream = service.oneshotSearch(query);

        InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
        try {
            OutputStreamWriter writer = new OutputStreamWriter(System.out);
            try {
View Full Code Here


        }
    }

    static void run(String[] args) throws IOException {
        Command command = Command.splunk("test").parse(args);
        Service service = Service.connect(command.opts);

        String path = command.args.length > 0 ? command.args[0] : "/";
        ResponseMessage response = service.get(path);

        int status = response.getStatus();
        System.out.println(String.format("=> %d", status));
        if (status != 200) return;
View Full Code Here

        args.put("scheme", service.getScheme());
        args.put("username", service.getUsername());
        args.put("password", service.getPassword());
        args.put("app", app);
        args.put("owner", "-");
        Service scope = Service.connect(args);

        Node node = new ExplorerNode(scope, new NamespaceKids(scope));
        node.setDisplayName(displayName);
        return node;
    }
View Full Code Here

public class Program {
    public static void main(final String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Command command = Command.splunk("explorer").parse(args);
                Service service = Service.connect(command.opts);
                Explorer.create(service).setVisible(true);
            }
        });
    }
View Full Code Here

        String outputMode = "xml";
        if (command.opts.containsKey("output_mode"))
            outputMode = (String)command.opts.get("output_mode");

        Service service = Service.connect(command.opts);

        // Check the syntax of the query.
        try {
            Args parseArgs = new Args("parse_only", true);
            service.parse(query, parseArgs);
        }
        catch (HttpException e) {
            String detail = e.getDetail();
            Command.error("query '%s' is invalid: %s", query, detail);
        }

        // Create the oneshot search query & query arguments.
        Args queryArgs = new Args();
        if (earliestTime != null)
            queryArgs.put("earliest_time", earliestTime);
        if (fieldList != null)
            queryArgs.put("field_list", fieldList);
        if (latestTime != null)
            queryArgs.put("latest_time", latestTime);
        if (statusBuckets > 0)
            queryArgs.put("status_buckets", statusBuckets);
        queryArgs.put("output_mode", outputMode);

        // Execute the oneshot query, which returns the stream (i.e. there is
        // no search job created, just a one time search)
        InputStream stream = service.oneshotSearch(query, queryArgs);

        boolean rawData = true;
        if (command.opts.containsKey("raw")) {
            int tmp  = (Integer)command.opts.get("raw");
            if (tmp == 0 ) rawData = false;
View Full Code Here

        }
    }

    public static void main(String[] args) {
        Command command = Command.splunk("index").parse(args);
        Service service = Service.connect(command.opts);

        // This example takes optional arguments:
        // [action index-name]
        //
        // without cli arguments, all indexes and their totalEventCount
        // is displayed

        if (command.args.length == 0) {
            list(service);
            return;
        }

        if (command.args.length != 2)
            Command.error("Action and index-name required");

        String action = command.args[0];
        String name = command.args[1];

        EntityCollection<Index> indexes = service.getIndexes();
        if (action.equals("create")) {
            if (indexes.containsKey(name))
                Command.error("Index " + name + " already exists");
            indexes.create(name);
            return;
View Full Code Here

        SavedSearch search = null;
        Job job = null;
        String latestTime = getLatestTime(startTime, false);
        String earliestTime = getEarliestTime(startTime, false);

        Service service = endpoint.getService();
        SavedSearchCollection savedSearches = service.getSavedSearches(queryArgs);
        for (SavedSearch s : savedSearches.values()) {
            if (s.getName().equals(getSavedSearch())) {
                search = s;
                break;
            }
View Full Code Here

        lastSuccessfulReadTime = startTime;
        return data;
    }

    private List<SplunkEvent> runQuery(JobArgs queryArgs, boolean realtime) throws Exception {
        Service service = endpoint.getService();
        Job job = service.getJobs().create(getSearch(), queryArgs);
        LOG.debug("Running search : {} with queryArgs : {}", getSearch(), queryArgs);
        if (realtime) {
            while (!job.isReady()) {
                Thread.sleep(500);
            }
View Full Code Here

            public Service call() throws Exception {
                return Service.connect(args);
            }
        });
        try {
            Service service = null;
            if (connectionTimeout > 0) {
                service = future.get(connectionTimeout, TimeUnit.MILLISECONDS);
            } else {
                service = future.get();
            }
View Full Code Here

        SavedSearch search = null;
        Job job = null;
        String latestTime = getLatestTime(startTime, false);
        String earliestTime = getEarliestTime(startTime, false);

        Service service = endpoint.getService();
        SavedSearchCollection savedSearches = service.getSavedSearches(queryArgs);
        for (SavedSearch s : savedSearches.values()) {
            if (s.getName().equals(getSavedSearch())) {
                search = s;
                break;
            }
View Full Code Here

TOP

Related Classes of com.splunk.Service

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.