com.googlecode.jsendnsca.MessagePayload Java Examples
The following examples show how to use
com.googlecode.jsendnsca.MessagePayload.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NagiosIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSendToNagios() throws Exception { CamelContext camelctx = createCamelContext(); MessagePayload expectedPayload = new MessagePayload("localhost", Level.OK, camelctx.getName(), "Hello Nagios"); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); mock.allMessages().body().isInstanceOf(String.class); mock.expectedBodiesReceived("Hello Nagios"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", "Hello Nagios"); mock.assertIsSatisfied(); Mockito.verify(nagiosPassiveCheckSender, Mockito.times(1)).send(expectedPayload); } finally { camelctx.close(); } }
Example #2
Source File: NagiosIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSendToNagiosWarn() throws Exception { CamelContext camelctx = createCamelContext(); MessagePayload expectedPayload1 = new MessagePayload("localhost", Level.WARNING, camelctx.getName(), "Hello Nagios"); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); mock.expectedBodiesReceived("Hello Nagios"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:start", "Hello Nagios", NagiosConstants.LEVEL, Level.WARNING); mock.assertIsSatisfied(); Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload1); } finally { camelctx.close(); } }
Example #3
Source File: NagiosIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSendToNagiosWarnAsText() throws Exception { CamelContext camelctx = createCamelContext(); MessagePayload expectedPayload1 = new MessagePayload("localhost", Level.WARNING, camelctx.getName(), "Hello Nagios"); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); mock.expectedBodiesReceived("Hello Nagios"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:start", "Hello Nagios", NagiosConstants.LEVEL, "WARNING"); mock.assertIsSatisfied(); Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload1); } finally { camelctx.close(); } }
Example #4
Source File: NagiosIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSendTwoToNagios() throws Exception { CamelContext camelctx = createCamelContext(); MessagePayload expectedPayload1 = new MessagePayload("localhost", Level.OK, camelctx.getName(), "Hello Nagios"); MessagePayload expectedPayload2 = new MessagePayload("localhost", Level.OK, camelctx.getName(), "Bye Nagios"); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(2); mock.allMessages().body().isInstanceOf(String.class); mock.expectedBodiesReceived("Hello Nagios", "Bye Nagios"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", "Hello Nagios"); template.sendBody("direct:start", "Bye Nagios"); mock.assertIsSatisfied(); Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload1); Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload2); } finally { camelctx.close(); } }
Example #5
Source File: NagiosIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSendToNagiosMultiHeaders() throws Exception { CamelContext camelctx = createCamelContext(); MessagePayload expectedPayload1 = new MessagePayload("myHost", Level.CRITICAL, "myService", "Hello Nagios"); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); mock.expectedBodiesReceived("Hello Nagios"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(NagiosConstants.LEVEL, "CRITICAL"); headers.put(NagiosConstants.HOST_NAME, "myHost"); headers.put(NagiosConstants.SERVICE_NAME, "myService"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeaders("direct:start", "Hello Nagios", headers); mock.assertIsSatisfied(); Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload1); } finally { camelctx.close(); } }
Example #6
Source File: ActionSendNagiosPassiveICheck.java From hop with Apache License 2.0 | 4 votes |
public Result execute( Result previousResult, int nr ) { log.logBasic( BaseMessages.getString( PKG, "ActionSendNagiosPassiveCheck.Started", serverName ) ); Result result = previousResult; result.setNrErrors( 1 ); result.setResult( false ); // Target String realServername = environmentSubstitute( serverName ); String realPassword = Utils.resolvePassword( variables, password ); int realPort = Const.toInt( environmentSubstitute( port ), DEFAULT_PORT ); int realResponseTimeOut = Const.toInt( environmentSubstitute( responseTimeOut ), DEFAULT_RESPONSE_TIME_OUT ); int realConnectionTimeOut = Const.toInt( environmentSubstitute( connectionTimeOut ), DEFAULT_CONNECTION_TIME_OUT ); // Sender String realSenderServerName = environmentSubstitute( senderServerName ); String realSenderServiceName = environmentSubstitute( senderServiceName ); try { if ( Utils.isEmpty( realServername ) ) { throw new HopException( BaseMessages.getString( PKG, "JobSendNagiosPassiveCheck.Error.TargetServerMissing" ) ); } String realMessageString = environmentSubstitute( message ); if ( Utils.isEmpty( realMessageString ) ) { throw new HopException( BaseMessages.getString( PKG, "JobSendNagiosPassiveCheck.Error.MessageMissing" ) ); } Level level = Level.UNKNOWN; switch ( getLevel() ) { case LEVEL_TYPE_OK: level = Level.OK; break; case LEVEL_TYPE_CRITICAL: level = Level.CRITICAL; break; case LEVEL_TYPE_WARNING: level = Level.WARNING; break; default: break; } Encryption encr = Encryption.NONE; switch ( getEncryptionMode() ) { case ENCRYPTION_MODE_TRIPLEDES: encr = Encryption.TRIPLE_DES; break; case ENCRYPTION_MODE_XOR: encr = Encryption.XOR; break; default: break; } // settings NagiosSettingsBuilder ns = new NagiosSettingsBuilder(); ns.withNagiosHost( realServername ); ns.withPort( realPort ); ns.withConnectionTimeout( realConnectionTimeOut ); ns.withResponseTimeout( realResponseTimeOut ); ns.withEncryption( encr ); if ( !Utils.isEmpty( realPassword ) ) { ns.withPassword( realPassword ); } else { ns.withNoPassword(); } // target nagios host NagiosSettings settings = ns.create(); // sender MessagePayloadBuilder pb = new MessagePayloadBuilder(); if ( !Utils.isEmpty( realSenderServerName ) ) { pb.withHostname( realSenderServerName ); } pb.withLevel( level ); if ( !Utils.isEmpty( realSenderServiceName ) ) { pb.withServiceName( realSenderServiceName ); } pb.withMessage( realMessageString ); MessagePayload payload = pb.create(); NagiosPassiveCheckSender sender = new NagiosPassiveCheckSender( settings ); sender.send( payload ); result.setNrErrors( 0 ); result.setResult( true ); } catch ( Exception e ) { log.logError( BaseMessages.getString( PKG, "ActionSendNagiosPassiveCheck.ErrorGetting", e.toString() ) ); } return result; }
Example #7
Source File: JobEntrySendNagiosPassiveCheck.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public Result execute( Result previousResult, int nr ) { log.logBasic( BaseMessages.getString( PKG, "JobEntrySendNagiosPassiveCheck.Started", serverName ) ); Result result = previousResult; result.setNrErrors( 1 ); result.setResult( false ); // Target String realServername = environmentSubstitute( serverName ); String realPassword = Utils.resolvePassword( variables, password ); int realPort = Const.toInt( environmentSubstitute( port ), DEFAULT_PORT ); int realResponseTimeOut = Const.toInt( environmentSubstitute( responseTimeOut ), DEFAULT_RESPONSE_TIME_OUT ); int realConnectionTimeOut = Const.toInt( environmentSubstitute( connectionTimeOut ), DEFAULT_CONNECTION_TIME_OUT ); // Sender String realSenderServerName = environmentSubstitute( senderServerName ); String realSenderServiceName = environmentSubstitute( senderServiceName ); try { if ( Utils.isEmpty( realServername ) ) { throw new KettleException( BaseMessages.getString( PKG, "JobSendNagiosPassiveCheck.Error.TargetServerMissing" ) ); } String realMessageString = environmentSubstitute( message ); if ( Utils.isEmpty( realMessageString ) ) { throw new KettleException( BaseMessages.getString( PKG, "JobSendNagiosPassiveCheck.Error.MessageMissing" ) ); } Level level = Level.UNKNOWN; switch ( getLevel() ) { case LEVEL_TYPE_OK: level = Level.OK; break; case LEVEL_TYPE_CRITICAL: level = Level.CRITICAL; break; case LEVEL_TYPE_WARNING: level = Level.WARNING; break; default: break; } Encryption encr = Encryption.NONE; switch ( getEncryptionMode() ) { case ENCRYPTION_MODE_TRIPLEDES: encr = Encryption.TRIPLE_DES; break; case ENCRYPTION_MODE_XOR: encr = Encryption.XOR; break; default: break; } // settings NagiosSettingsBuilder ns = new NagiosSettingsBuilder(); ns.withNagiosHost( realServername ); ns.withPort( realPort ); ns.withConnectionTimeout( realConnectionTimeOut ); ns.withResponseTimeout( realResponseTimeOut ); ns.withEncryption( encr ); if ( !Utils.isEmpty( realPassword ) ) { ns.withPassword( realPassword ); } else { ns.withNoPassword(); } // target nagios host NagiosSettings settings = ns.create(); // sender MessagePayloadBuilder pb = new MessagePayloadBuilder(); if ( !Utils.isEmpty( realSenderServerName ) ) { pb.withHostname( realSenderServerName ); } pb.withLevel( level ); if ( !Utils.isEmpty( realSenderServiceName ) ) { pb.withServiceName( realSenderServiceName ); } pb.withMessage( realMessageString ); MessagePayload payload = pb.create(); NagiosPassiveCheckSender sender = new NagiosPassiveCheckSender( settings ); sender.send( payload ); result.setNrErrors( 0 ); result.setResult( true ); } catch ( Exception e ) { log.logError( BaseMessages.getString( PKG, "JobEntrySendNagiosPassiveCheck.ErrorGetting", e.toString() ) ); } return result; }