Package org.rhq.core.domain.alert.notification

Examples of org.rhq.core.domain.alert.notification.SenderResult


                            if (notificationSender == null) {
                                notificationLog = new AlertNotificationLog(alert, senderName, ResultState.FAILURE,
                                    "Failed to obtain a sender with given name");
                            } else {
                                try {
                                    SenderResult result = notificationSender.send(alert);
                                    if (log.isDebugEnabled()) {
                                        log.debug(result);
                                    }

                                    if (result == null) {
View Full Code Here


        String token;
        try {
            token = getToken();
        } catch (Exception e) {
            SenderResult senderResult = new SenderResult();
            senderResult.addFailureMessage("Can not obtain token: " + e.getMessage());
            return senderResult;
        }

        Resource res = alert.getAlertDefinition().getResource();
        Integer alertId = alert.getId();

        StringBuilder b = new StringBuilder();
        b.append("Alert ");
        b.append("(").append(alertId).append("): ");
        b.append(res.getName());
        b.append(",id=(").append(res.getId()).append(")");
        b.append("Brought by RHQ");

        try {
            sendAlertSms(token,b.toString());
        } catch (Exception e) {
            SenderResult senderResult = new SenderResult();
            senderResult.addFailureMessage("Failed to send SMS: " + e.getMessage());
            return senderResult;
        }

        SenderResult senderResult = new SenderResult();
        String tel = alertParameters.getSimpleValue("tel",null);
        senderResult.addSuccessMessage("SMS to " + tel + " sent");
        return senderResult;
    }
View Full Code Here

    private final Log log = LogFactory.getLog(MicroblogSender.class);

    @Override
    public SenderResult send(Alert alert) {

        SenderResult result;
        String consumerKey = preferences.getSimpleValue("consumerKey", CONS_KEY);
        String consumerSecret = preferences.getSimpleValue("consumerSecret",
                CONS_SECRET);
        String accessTokenFilePath = preferences.getSimpleValue("accessTokenFilePath", "/path/to/token.ser");
View Full Code Here

        String scriptFileExtension;
    }

    @Override
    public SenderResult send(Alert alert) {
        SenderResult result = new SenderResult();
        BufferedReader reader = null;
        ScriptEngine engine = null;
        Subject subjectWithSession = null;
        final SessionManager sessionManager = SessionManager.getInstance();
        String language = null;

        try {
            final Config config = getConfig();

            // simulate the login by getting a session ID
            config.subject = sessionManager.put(config.subject, pluginComponent.getScriptTimeout() * 1000);
            subjectWithSession = config.subject;

            result.setSummary(createSummary(config, SUMMARY_TEMPLATE));

            ByteArrayOutputStream scriptOutputStream = new ByteArrayOutputStream();
            PrintWriter scriptOut = new PrintWriter(scriptOutputStream);

            BitsAndFileExtension packageData = getPackageBits(config.packageId, config.repoId);

            InputStream packageBits = packageData.packageBits;
            String scriptFileExtension = packageData.scriptFileExtension;
            language = ScriptEngineFactory.getLanguageByScriptFileExtension(scriptFileExtension);

            if (language == null) {
                ArrayList<String> supportedExtensions = new ArrayList<String>();
                for (String lang : ScriptEngineFactory.getSupportedLanguages()) {
                    supportedExtensions.add(ScriptEngineFactory.getFileExtensionForLanguage(lang));
                }

                throw new IllegalArgumentException(
                    "Could not determine the script engine to use based on the script file extension '"
                        + scriptFileExtension + "'. Only the following extensions are currently supported: "
                        + supportedExtensions);
            }

            engine = getScriptEngine(alert, scriptOut, config, language, pluginComponent.getDomainPackagesNames());

            reader = new BufferedReader(new InputStreamReader(packageBits));

            final BufferedReader rdr = reader;

            final ExceptionHolder exceptionHolder = new ExceptionHolder();

            final ScriptEngine e = engine;
            Thread scriptRunner = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        e.eval(rdr);
                    } catch (ScriptException e) {
                        exceptionHolder.scriptException = e;
                    } catch (Throwable e) {
                        exceptionHolder.throwable = e;
                    }
                }
            }, "Script Runner for alert " + alert);
            scriptRunner.setDaemon(true);
            scriptRunner.start();

            if (pluginComponent.getScriptTimeout() <= 0) {
                scriptRunner.join();
            } else {
                scriptRunner.join(pluginComponent.getScriptTimeout() * 1000);
            }

            scriptRunner.interrupt();

            if (exceptionHolder.scriptException != null) {
                LOG.info("The script execution for CLI notification of alert [" + alert + "] failed.",
                    exceptionHolder.scriptException);

                //make things pretty for the UI
                ScriptEngineInitializer initializer = ScriptEngineFactory.getInitializer(language);
                String message = initializer.extractUserFriendlyErrorMessage(exceptionHolder.scriptException);
                int col = exceptionHolder.scriptException.getColumnNumber();
                int line = exceptionHolder.scriptException.getLineNumber();
                String scriptName = createSummary(config, "script $packageName ($packageVersion) in repo $repoName");
                throw new ScriptException(message, scriptName, line, col);
            } else if (exceptionHolder.throwable != null) {
                LOG.info("The script execution for CLI notification of alert [" + alert + "] failed.",
                    exceptionHolder.throwable);

                throw exceptionHolder.throwable;
            }

            scriptOut.flush();
            String scriptOutput = scriptOutputStream.toString(Charset.defaultCharset().name());

            if (scriptOutput.length() == 0) {
                scriptOutput = "Script generated no output.";
            }

            if (scriptOutput.length() > remainingResultSize(result)) {
                scriptOutput = scriptOutput.substring(0, remainingResultSize(result));
            }

            result.addSuccessMessage(scriptOutput);

            return result;
        } catch (IllegalArgumentException e) {
            return SenderResult.getSimpleFailure(e.getMessage()); //well, let's just hope the message doesn't exceed 4k.
        } catch (Throwable e) {
            result.addFailureMessage(ThrowableUtil.getAllMessages(e, true, remainingResultSize(result)));
            return result;
        } finally {
            if (subjectWithSession != null) {
                sessionManager.invalidate(subjectWithSession.getSessionId());
            }
View Full Code Here

                .sendAlertNotificationEmails(alert, uniqueEmails);

            List<String> goodEmails = new ArrayList<String>(uniqueEmails);
            goodEmails.removeAll(badEmails);

            SenderResult result = new SenderResult();
            result.setSummary("Target addresses were: " + uniqueEmails);
            if (goodEmails.size() > 0) {
                result.addSuccessMessage("Successfully sent to: " + goodEmails);
            }
            if (badEmails.size() > 0) {
                result.addFailureMessage("Failed to send to: " + badEmails);
            }
            return result;
        } catch (Throwable t) {
            return SenderResult.getSimpleFailure("Error sending email notifications to " + emails + ", cause: "
                + t.getMessage());
View Full Code Here

                .sendAlertNotificationEmails(alert, uniqueEmails);

            List<String> goodEmails = new ArrayList<String>(uniqueEmails);
            goodEmails.removeAll(badEmails);

            SenderResult result = new SenderResult();
            result.setSummary("Target roles were: " + names);
            if (goodEmails.size() > 0) {
                result.addSuccessMessage("Successfully sent to: " + goodEmails);
            }
            if (badEmails.size() > 0) {
                result.addFailureMessage("Failed to send to: " + badEmails);
            }
            return result;
        } catch (Throwable t) {
            return SenderResult.getSimpleFailure("Error sending role notifications to " + names + ", cause: "
                + t.getMessage());
View Full Code Here

    @Test
    public void shouldReturnSimpleFailureForInvalidNotificationParameters() {
        Configuration alertParameters = new Configuration();
        snmpSender.setAlertParameters(alertParameters);

        SenderResult result = snmpSender.send(createAlertForResourceWithId(13004, "", "", HIGH));

        assertNotNull(result);
        assertEquals(result.getState(), FAILURE);
        assertEquals(result.getFailureMessages().size(), 1);
        String expectedError = SnmpInfo.load(alertParameters,pluginConfiguration).error;
        assertNotNull(expectedError);
        assertEquals(result.getFailureMessages().get(0), expectedError);
    }
View Full Code Here

        int resourceId = 13004;
        Alert alert = createAlertForResourceWithId(resourceId, "", "", HIGH);
        String exceptionMessage = "Test Error";
        when(resourceManager.getResourceLineage(eq(resourceId))).thenThrow(new RuntimeException(exceptionMessage));

        SenderResult result = snmpSender.send(alert);

        assertNotNull(result);
        assertEquals(result.getState(), FAILURE);
        assertEquals(result.getFailureMessages().size(), 1);
        String actualErrorMessage = result.getFailureMessages().get(0);
        assertTrue(actualErrorMessage.endsWith(exceptionMessage), "Unexpected error message: " + actualErrorMessage);
    }
View Full Code Here

        String alertUrl = "https://www.rhq.com/alert/" + resourceId;
        when(alertManager.prettyPrintAlertURL(eq(alert))).thenReturn(alertUrl);

        assertNull(receivedTraps.peek(), "Something sent a trap before on our test port");

        SenderResult result = snmpSender.send(alert);

        assertEquals(result.getState(), SUCCESS, result.getFailureMessages().toString());
        while (receivedTraps.peek() == null) {
            Thread.sleep(1000);
        }
        PDU pdu = receivedTraps.poll();
        assertNull(receivedTraps.peek(), "Only one trap should have been received");
View Full Code Here

                .sendAlertNotificationEmails(alert, uniqueEmails);

            List<String> goodEmails = new ArrayList<String>(uniqueEmails);
            goodEmails.removeAll(badEmails);

            SenderResult result = new SenderResult();
            result.setSummary("Target subjects were: " + names);
            if (goodEmails.size() > 0) {
                result.addSuccessMessage("Successfully sent to: " + goodEmails);
            }
            if (badEmails.size() > 0) {
                result.addFailureMessage("Failed to send to: " + badEmails);
            }
            return result;
        } catch (Throwable t) {
            return SenderResult.getSimpleFailure("Error sending subject notifications to " + names + ", cause: "
                + t.getMessage());
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.alert.notification.SenderResult

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.