package com.perforce.p4splunk; import java.io.IOException; import java.util.Map; import javax.xml.stream.XMLStreamException; import com.perforce.p4splunk.client.AuthorisationConfig; import com.perforce.p4splunk.client.ConnectionConfig; import com.perforce.p4splunk.client.ConnectionFactory; import com.splunk.modularinput.Argument; import com.splunk.modularinput.EventWriter; import com.splunk.modularinput.InputDefinition; import com.splunk.modularinput.MalformedDataException; import com.splunk.modularinput.Parameter; import com.splunk.modularinput.Scheme; import com.splunk.modularinput.Script; import com.splunk.modularinput.SingleValueParameter; import com.splunk.modularinput.ValidationDefinition; public class Main extends Script { public static void main(String[] args) { new Main().run(args); } @Override public Scheme getScheme() { Scheme scheme = new Scheme("perforce_jnl"); scheme.setDescription("Generates events containing a random number."); scheme.setUseExternalValidation(true); scheme.setUseSingleInstance(true); // Update README/inputs.conf.spec. Argument p4port = new Argument("p4port"); p4port.setDataType(Argument.DataType.STRING); p4port.setDescription("Perforce server port e.g. 'localhost:1666'"); p4port.setRequiredOnCreate(true); scheme.addArgument(p4port); Argument p4user = new Argument("p4user"); p4user.setDataType(Argument.DataType.STRING); p4user.setDescription("Username to authenticate against the Perforce server"); p4user.setRequiredOnCreate(true); scheme.addArgument(p4user); Argument p4pass = new Argument("p4pass"); p4pass.setDataType(Argument.DataType.STRING); p4pass.setDescription("Password or Ticket to authenticate against the Perforce server"); p4pass.setRequiredOnCreate(false); scheme.addArgument(p4pass); Argument table = new Argument("table"); table.setDataType(Argument.DataType.STRING); table.setDescription("Filter on a specific Perforce db table (e.g. db.user)"); table.setRequiredOnCreate(false); scheme.addArgument(table); Argument limit = new Argument("limit"); limit.setDataType(Argument.DataType.NUMBER); limit.setDescription("Batch size of Journal entries to read."); limit.setRequiredOnCreate(false); scheme.addArgument(limit); Argument jnlStartIndex = new Argument("jnlStartIndex"); jnlStartIndex.setDataType(Argument.DataType.STRING); jnlStartIndex.setDescription("Journal Start Index."); jnlStartIndex.setRequiredOnCreate(false); scheme.addArgument(jnlStartIndex); return scheme; } @Override public void validateInput(ValidationDefinition definition) throws Exception { Map<String, Parameter> params = definition.getParameters(); String p4port = ((SingleValueParameter) params.get("p4port")) .getValue(); if (p4port == null || p4port.isEmpty()) { throw new Exception("p4port not defined!"); } String p4user = ((SingleValueParameter) params.get("p4user")) .getValue(); if (p4user == null || p4user.isEmpty()) { throw new Exception("p4user not defined!"); } ConnectionConfig config = new ConnectionConfig(params); String error = ConnectionFactory.testConnection(config); if (error != null) { throw new Exception(error); } } // Finally, the real action: splunk calls the modular input with no // arguments, streams a bunch of XML describing // the inputs to stdin, and waits for XML on stdout describing events. // // If you set setUseSingleInstance(true) on the scheme in getScheme, it will // pass all the instances of this input // to a single instance of this script and it's your job to handle them all. // Otherwise, it starts a JVM for each // instance of the input. // // We are using a single instance, and starting a thread for each instance // of the modular input. For scripts that // are not single instance, it is simpler to do the work directly in the // streamEvents method. @Override public void streamEvents(InputDefinition inputs, EventWriter ew) throws MalformedDataException, XMLStreamException, IOException { for (String name : inputs.getInputs().keySet()) { Map<String, Parameter> params = inputs.getInputs().get(name); ConnectionConfig connection = new ConnectionConfig(params); AuthorisationConfig auth = new AuthorisationConfig(params); JournalExport jnl = new JournalExport(ew, name); jnl.setConnection(connection); jnl.setAuthorisation(auth); jnl.setConfiguration(params); Thread t = new Thread(jnl); t.run(); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 10090 | Paul Allen |
Submit journal @pv@ entry as "key=value key=value etc..." + Basic password support + Journal limit and start index + Basic Journal db table filter + Open/Close the Perforce connection each iteration |
||
#2 | 10077 | Paul Allen | Add export command -- not yet working. | ||
#1 | 10058 | Paul Allen | Java version of Perforce Modular Input |