Search in sources :

Example 1 with SnmpDriver

use of org.openmuc.framework.driver.snmp.SnmpDriver in project OpenMUC by isc-konstanz.

the class SnmpScannerExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    SnmpDriver myDriver = new SnmpDriver();
    String settings = SnmpDriverSettingVariableNames.AUTHENTICATIONPASSPHRASE + "=adminadmin:" + SnmpDriverScanSettingVariableNames.STARTIP + "=192.168.1.0:" + SnmpDriverScanSettingVariableNames.ENDIP + "=192.168.10.0";
    class TestListener implements DriverDeviceScanListener {

        @Override
        public void scanProgressUpdate(int progress) {
        }

        @Override
        public void deviceFound(DeviceScanInfo device) {
            System.out.println("-----------------------------");
            System.out.println("New device found: ");
            System.out.println("Address: " + device.getAddress());
            System.out.println("Description: " + device.getDescription());
            System.out.println("-----------------------------");
        }
    }
    ;
    TestListener listener = new TestListener();
    try {
        myDriver.scanForDevices(settings, listener);
        Thread.sleep(100);
    } catch (InterruptedException iex) {
        System.out.println("Request cancelled: " + iex.getMessage());
    } catch (ArgumentSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ScanException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ScanInterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) SnmpDriver(org.openmuc.framework.driver.snmp.SnmpDriver) ScanException(org.openmuc.framework.config.ScanException) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException)

Example 2 with SnmpDriver

use of org.openmuc.framework.driver.snmp.SnmpDriver in project OpenMUC by isc-konstanz.

the class UsecaseExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        SnmpDriver snmpDriver = new SnmpDriver();
        // SNMPVersion=V2c:COMMUNITY=root:SECURITYNAME=root:AUTHENTICATIONPASSPHRASE=adminadmin:PRIVACYPASSPHRASE=adminadmin
        String settings = SnmpDriverSettingVariableNames.SNMP_VERSION + "=" + SNMPVersion.V2c + ":" + SnmpDriverSettingVariableNames.USERNAME + "=root:" + SnmpDriverSettingVariableNames.SECURITYNAME + "=root:" + SnmpDriverSettingVariableNames.AUTHENTICATIONPASSPHRASE + "=adminadmin:" + SnmpDriverSettingVariableNames.PRIVACYPASSPHRASE + "=adminadmin";
        System.out.println(settings);
        SnmpDevice myDevice = (SnmpDevice) snmpDriver.connect("192.168.1.1/161", settings);
        List<ChannelRecordContainer> containers = new ArrayList<>();
        SnmpChannel ch1 = new SnmpChannel("192.168.1.1/161", "1.3.6.1.2.1.1.1.0");
        SnmpChannel ch2 = new SnmpChannel("192.168.1.1/161", "1.3.6.1.2.1.25.1.1.0");
        SnmpChannel ch3 = new SnmpChannel("192.168.1.1/161", "1.3.6.1.2.1.1.5.0");
        containers.add(new SnmpChannelRecordContainer(ch1));
        containers.add(new SnmpChannelRecordContainer(ch2));
        containers.add(new SnmpChannelRecordContainer(ch3));
        myDevice.read(containers, null, null);
        for (ChannelRecordContainer container : containers) {
            if (container.getRecord() != null) {
                System.out.println(container.getRecord().getValue());
            }
        }
    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ArgumentSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) SnmpDriver(org.openmuc.framework.driver.snmp.SnmpDriver) SnmpDevice(org.openmuc.framework.driver.snmp.implementation.SnmpDevice) ArrayList(java.util.ArrayList) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 3 with SnmpDriver

use of org.openmuc.framework.driver.snmp.SnmpDriver in project OpenMUC by isc-konstanz.

the class SnmpTest method beforeClass.

@BeforeAll
public static void beforeClass() {
    snmpDriver = new SnmpDriver();
    correctSetting = SnmpDriverSettingVariableNames.USERNAME + "=username:" + SnmpDriverSettingVariableNames.SECURITYNAME + "=securityname:" + SnmpDriverSettingVariableNames.AUTHENTICATIONPASSPHRASE + "=password:" + SnmpDriverSettingVariableNames.PRIVACYPASSPHRASE + "=privacy";
}
Also used : SnmpDriver(org.openmuc.framework.driver.snmp.SnmpDriver) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

SnmpDriver (org.openmuc.framework.driver.snmp.SnmpDriver)3 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)2 ArrayList (java.util.ArrayList)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)1 ScanException (org.openmuc.framework.config.ScanException)1 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)1 SnmpDevice (org.openmuc.framework.driver.snmp.implementation.SnmpDevice)1 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1 DriverDeviceScanListener (org.openmuc.framework.driver.spi.DriverDeviceScanListener)1