Search in sources :

Example 1 with Slf4jLogAdapter

use of org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter in project opennms by OpenNMS.

the class GenerateConfigsJob method execute.

@Override
public Void execute() throws JobManager.TaskRunException {
    // create snmp-graph.properties
    GraphConfigGenerator graphConfigGenerator = new GraphConfigGenerator(new Slf4jLogAdapter(GraphConfigGenerator.class));
    Collection<Report> reports = new JmxConfigReader(new Slf4jLogAdapter(JmxConfigReader.class)).generateReportsByJmxDatacollectionConfig(model.getOutputConfig());
    model.setSnmpGraphProperties(graphConfigGenerator.generateSnmpGraph(reports));
    model.updateOutput();
    return null;
}
Also used : JmxConfigReader(org.opennms.features.jmxconfiggenerator.graphs.JmxConfigReader) Report(org.opennms.features.jmxconfiggenerator.graphs.Report) Slf4jLogAdapter(org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter) GraphConfigGenerator(org.opennms.features.jmxconfiggenerator.graphs.GraphConfigGenerator)

Example 2 with Slf4jLogAdapter

use of org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter in project opennms by OpenNMS.

the class JmxDatacollectionConfiggeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    jmxConfiggenerator = new JmxDatacollectionConfiggenerator(new Slf4jLogAdapter(JmxDatacollectionConfiggenerator.class));
    platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    testObjectName = new ObjectName("org.opennms.tools.jmxconfiggenerator.jmxconfig:type=JmxTest");
    testMBean = new JmxTestDummy();
    platformMBeanServer.registerMBean(testMBean, testObjectName);
}
Also used : Slf4jLogAdapter(org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Example 3 with Slf4jLogAdapter

use of org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter in project opennms by OpenNMS.

the class DetectMBeansJob method execute.

@Override
public JmxDatacollectionConfig execute() throws JobManager.TaskRunException {
    final JmxConnectionConfig connectionConfig = new JmxConnectionConfigBuilder().withUrl(config.getConnection()).withUsername(config.getUser()).withPassword(config.getPassword()).build();
    try (JmxServerConnectionWrapper connector = new DefaultJmxConnector().createConnection(connectionConfig)) {
        final JmxDatacollectionConfiggenerator jmxConfigGenerator = new JmxDatacollectionConfiggenerator(new Slf4jLogAdapter(JmxDatacollectionConfiggenerator.class));
        final JmxDatacollectionConfig generatedJmxConfigModel = jmxConfigGenerator.generateJmxConfigModel(connector.getMBeanServerConnection(), "anyservice", !config.isSkipDefaultVM(), config.isSkipNonNumber(), JmxHelper.loadInternalDictionary());
        applyFilters(generatedJmxConfigModel);
        return generatedJmxConfigModel;
    } catch (IOException | MBeanServerQueryException | JMException | JmxServerConnectionException e) {
        if (e instanceof UnknownHostException || e.getCause() instanceof UnknownHostException) {
            throw new JobManager.TaskRunException(String.format("Unknown host: %s", config.getConnection()), e);
        }
        if (e instanceof MalformedURLException || e.getCause() instanceof MalformedURLException) {
            throw new JobManager.TaskRunException(String.format("Cannot create valid JMX Connection URL. Connection: '%s'", config.getConnection()), e);
        }
        throw new JobManager.TaskRunException("Error while retrieving MBeans from server.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) Slf4jLogAdapter(org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) IOException(java.io.IOException) JmxConnectionConfig(org.opennms.netmgt.jmx.connection.JmxConnectionConfig) JmxServerConnectionException(org.opennms.netmgt.jmx.connection.JmxServerConnectionException) JmxDatacollectionConfiggenerator(org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator) DefaultJmxConnector(org.opennms.netmgt.jmx.impl.connection.connectors.DefaultJmxConnector) JMException(javax.management.JMException) JmxServerConnectionWrapper(org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper) JmxConnectionConfigBuilder(org.opennms.netmgt.jmx.connection.JmxConnectionConfigBuilder)

Example 4 with Slf4jLogAdapter

use of org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter in project opennms by OpenNMS.

the class GraphConfigGeneratorTest method verifyGraphGeneration.

@Test
public void verifyGraphGeneration() {
    JmxConfigReader jmxConfigReader = new JmxConfigReader(new Slf4jLogAdapter(JmxConfigReader.class));
    Collection<Report> reports = jmxConfigReader.generateReportsByJmxDatacollectionConfig(getClass().getResourceAsStream("/cassandra21x-datacollection-config.xml"));
    GraphConfigGenerator graphConfigGenerator = new GraphConfigGenerator(new Slf4jLogAdapter(GraphConfigGenerator.class));
    String snmpGraph = graphConfigGenerator.generateSnmpGraph(reports);
    Assert.assertNotNull(snmpGraph);
}
Also used : Slf4jLogAdapter(org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter) Test(org.junit.Test)

Aggregations

Slf4jLogAdapter (org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter)4 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 JMException (javax.management.JMException)1 ObjectName (javax.management.ObjectName)1 Before (org.junit.Before)1 Test (org.junit.Test)1 GraphConfigGenerator (org.opennms.features.jmxconfiggenerator.graphs.GraphConfigGenerator)1 JmxConfigReader (org.opennms.features.jmxconfiggenerator.graphs.JmxConfigReader)1 Report (org.opennms.features.jmxconfiggenerator.graphs.Report)1 JmxDatacollectionConfiggenerator (org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator)1 MBeanServerQueryException (org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException)1 JmxDatacollectionConfig (org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig)1 JmxConnectionConfig (org.opennms.netmgt.jmx.connection.JmxConnectionConfig)1 JmxConnectionConfigBuilder (org.opennms.netmgt.jmx.connection.JmxConnectionConfigBuilder)1 JmxServerConnectionException (org.opennms.netmgt.jmx.connection.JmxServerConnectionException)1 JmxServerConnectionWrapper (org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper)1 DefaultJmxConnector (org.opennms.netmgt.jmx.impl.connection.connectors.DefaultJmxConnector)1