本文整理汇总了Java中org.graylog2.plugin.alarms.callbacks.AlarmCallbackException类的典型用法代码示例。如果您正苦于以下问题:Java AlarmCallbackException类的具体用法?Java AlarmCallbackException怎么用?Java AlarmCallbackException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AlarmCallbackException类属于org.graylog2.plugin.alarms.callbacks包,在下文中一共展示了AlarmCallbackException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trigger
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
public void trigger (final Stream stream, final AlertCondition.CheckResult checkResult) throws AlarmCallbackException {
try {
BasicCredentials creds = new BasicCredentials (JIRAUserName, JIRAPassword);
jiraClient = new JiraClient(JIRAServerURL, creds);
if (isDuplicateJiraIssue() == false) {
createJIRAIssue();
}
} catch (Throwable ex) {
LOG.error("Error in trigger function" + ex.getMessage() + (ex.getCause() != null ? ", Cause=" + ex.getCause().getMessage() : ""), ex);
throw ex;
}
}
示例2: call
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Override
public void call(Stream stream, AlertCondition.CheckResult result) throws AlarmCallbackException {
final JiraClient client = new JiraClient(
configuration.getString(CK_INSTANCE_URL),
configuration.getString(CK_USERNAME),
configuration.getString(CK_PASSWORD)
);
JiraIssue jiraIssue = new JiraIssue(
configuration.getString(CK_PROJECT_KEY),
configuration.getString(CK_LABELS),
configuration.getString(CK_ISSUE_TYPE),
configuration.getString(CK_COMPONENTS),
configuration.getString(CK_PRIORITY),
buildTitle(stream),
buildDescription(stream, result, configuration)
);
try {
client.send(jiraIssue);
} catch (JiraClient.JiraClientException e) {
throw new RuntimeException(e.getMessage());
}
}
示例3: testCallFailsWithDisabledJob
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Test
public void testCallFailsWithDisabledJob() throws Exception {
final Stream mockStream = mock(Stream.class);
final AlertCondition.CheckResult checkResult = new AbstractAlertCondition.NegativeCheckResult(
new DummyAlertCondition(
mockStream,
"id",
new DateTime(2017, 3, 20, 0, 0, DateTimeZone.UTC),
"user",
Collections.emptyMap())
);
final Configuration configuration = new Configuration(VALID_CONFIG_SOURCE);
configuration.setString("api_token", token);
configuration.setString("job_id", "804f107a-cafe-babe-0000-deadbeef0001");
expectedException.expect(AlarmCallbackException.class);
expectedException.expectMessage("Failed to send alarm to Rundeck");
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
alarmCallback.call(mockStream, checkResult);
}
示例4: testCallFailsWithParameterizedJobWithoutParameters
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Test
public void testCallFailsWithParameterizedJobWithoutParameters() throws Exception {
final Stream mockStream = mock(Stream.class);
final AlertCondition.CheckResult checkResult = new AbstractAlertCondition.NegativeCheckResult(
new DummyAlertCondition(
mockStream,
"id",
new DateTime(2017, 3, 20, 0, 0, DateTimeZone.UTC),
"user",
Collections.emptyMap())
);
final Configuration configuration = new Configuration(VALID_CONFIG_SOURCE);
configuration.setString("api_token", token);
configuration.setString("job_id", "804f107a-cafe-babe-0000-deadbeef0003");
expectedException.expect(AlarmCallbackException.class);
expectedException.expectMessage("Failed to send alarm to Rundeck");
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
alarmCallback.call(mockStream, checkResult);
}
示例5: testCallFailsWithUnknownJob
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Test
public void testCallFailsWithUnknownJob() throws Exception {
final Stream mockStream = mock(Stream.class);
final AlertCondition.CheckResult checkResult = new AbstractAlertCondition.NegativeCheckResult(
new DummyAlertCondition(
mockStream,
"id",
new DateTime(2017, 3, 20, 0, 0, DateTimeZone.UTC),
"user",
Collections.emptyMap())
);
final Configuration configuration = new Configuration(VALID_CONFIG_SOURCE);
configuration.setString("api_token", token);
configuration.setString("job_id", "unknown");
expectedException.expect(AlarmCallbackException.class);
expectedException.expectMessage("Failed to send alarm to Rundeck");
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
alarmCallback.call(mockStream, checkResult);
}
示例6: getModel
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
private Map<String, Object> getModel(AlertCondition condition, AlertCondition.CheckResult alert) throws AlarmCallbackException {
Stream stream = condition.getStream();
List<Message> messages = new ArrayList<>();
for (MessageSummary messageSummary : alert.getMatchingMessages()) {
messages.add(messageSummary.getRawMessage());
}
HashMap<String, Object> model = new HashMap<>();
model.put("stream", stream);
model.put("check_result", alert);
if (graylogBaseUrl != null) {
model.put("stream_url", buildStreamDetailsURL(graylogBaseUrl, alert, stream));
}
model.put("backlog", messages);
model.put("backlog_size", messages.size());
return model;
}
示例7: trigger
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
public void trigger(Alarm alarm) throws AlarmCallbackException {
String[] nsca_hosts = host.split(",");
int limit = alarm.getStream().getAlarmMessageLimit();
int current = alarm.getMessageCount();
Level level = limit * 2 > current ? Level.WARNING : Level.CRITICAL;
for (String nsca_host : nsca_hosts) {
String[] nsca_host_parts = nsca_host.split(":");
NscaHost nscaHost = new NscaHost(this.senderHostName,
nsca_host_parts[0],
nsca_host_parts.length > 1 ? Integer
.parseInt(nsca_host_parts[0]) : 5667,
Encryption.XOR);
try {
nscaHost.send(level, "Stream: " + alarm.getStream().getTitle(),
alarm.getDescription());
} catch (Exception e) {
throw new AlarmCallbackException("Could not submit alert to "
+ nsca_host + ". IOException");
}
}
}
示例8: call
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Override
public void call(Stream arg0, CheckResult arg1)
throws AlarmCallbackException {
try {
Runtime.getRuntime().exec(new String[]{"bash","-c",configs.getString("bashCommand")});
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: getJIRACustomMD5Field
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
/**
* Return the name of the md5 custom field
* @param jira
* @param jiraIssue
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
private String getJIRACustomMD5Field () throws AlarmCallbackException {
String strJIRACustomMD5Field = null;
LOG.warn("It is more efficient to configure '" + JiraAlarmCallback.CK_JIRA_MD5_CUSTOM_FIELD + "' for MD5-hashing.");
try {
JSONObject customfields = Issue.getCreateMetadata(jiraClient.getRestClient(), JIRAProjectKey, JIRAIssueType);
for (Iterator<String> iterator = customfields.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
if (key.startsWith("customfield_")) {
JSONObject metaFields = customfields.getJSONObject(key);
if (metaFields.has("name") && JiraIssueClient.CONST_GRAYLOGMD5_DIGEST.equalsIgnoreCase(metaFields.getString("name"))) {
strJIRACustomMD5Field = key;
break;
}
}
}
} catch (JiraException ex) {
LOG.error("Error getting JIRA custom MD5 field=" + ex.getMessage() + (ex.getCause() != null ? ", Cause=" + ex.getCause().getMessage() : ""), ex);
throw new AlarmCallbackException("Failed retrieving MD5-field", ex);
}
return strJIRACustomMD5Field;
}
示例10: call
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Override
public void call(Stream stream, AlertCondition.CheckResult cr) throws AlarmCallbackException {
try {
sendAlert(stream, cr);
} catch (Exception e) {
LOG.error("Could not send alert to Alertflex (AlarmCallbackException)", e);
}
}
示例11: call
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Override
public void call(Stream stream, AlertCondition.CheckResult result) throws AlarmCallbackException {
final SlackClient client = new SlackClient(configuration);
SlackMessage message = createSlackMessage(configuration, buildFullMessageBody(stream, result));
try {
client.send(message);
} catch (SlackClient.SlackClientException e) {
throw new RuntimeException("Could not send message to Slack.", e);
}
}
示例12: call
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
@Override
public void call(Stream stream, AlertCondition.CheckResult result) throws AlarmCallbackException {
final HipChatTrigger trigger = new HipChatTrigger(
configuration.getString(CK_API_TOKEN),
configuration.getString(CK_ROOM),
configuration.getString(CK_COLOR),
configuration.getBoolean(CK_NOTIFY),
configuration.getString(CK_API_URL),
configuration.getString(CK_MESSAGE_TEMPLATE),
getGraylogBaseUrl(configuration.getString(CK_GRAYLOG_BASE_URL)));
trigger.trigger(result.getTriggeredCondition(), result);
}
示例13: getGraylogBaseUrl
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
protected static URI getGraylogBaseUrl(String graylogBaseUrlString) throws AlarmCallbackException {
if (graylogBaseUrlString == null || graylogBaseUrlString.trim().isEmpty()) {
return null;
}
try {
String urlWithoutTrailingSlash =
graylogBaseUrlString.endsWith("/") ? graylogBaseUrlString.substring(0, graylogBaseUrlString.length() - 1) : graylogBaseUrlString;
return new URI(urlWithoutTrailingSlash);
} catch (URISyntaxException e) {
throw new AlarmCallbackException("Graylog URL '" + graylogBaseUrlString + "' is not a valid URI.");
}
}
示例14: buildStreamDetailsURL
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
public static String buildStreamDetailsURL(URI baseUri, AlertCondition.CheckResult checkResult, Stream stream) throws AlarmCallbackException {
if (baseUri != null && !Strings.isNullOrEmpty(baseUri.getHost())) {
int time = 5;
if (checkResult.getTriggeredCondition().getParameters().get("time") != null) {
time = ((Integer) checkResult.getTriggeredCondition().getParameters().get("time")).intValue();
}
DateTime dateAlertEnd = checkResult.getTriggeredAt();
DateTime dateAlertStart = dateAlertEnd.minusMinutes(time);
String alertStart = Tools.getISO8601String(dateAlertStart);
String alertEnd = Tools.getISO8601String(dateAlertEnd);
return baseUri + "/streams/" + stream.getId() + "/messages?rangetype=absolute&from=" + alertStart + "&to=" + alertEnd + "&q=*";
} else {
throw new AlarmCallbackException("Please configure a valid Graylog Base URL in the alarm callback parameters.");
}
}
示例15: buildBody
import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException; //导入依赖的package包/类
private String buildBody(AlertCondition condition, AlertCondition.CheckResult alert) throws AlarmCallbackException {
String template;
if (invalidTemplate(this.messageTemplate)) {
template = FormattedEmailAlertSender.bodyTemplate;
} else {
template = this.messageTemplate;
}
Map<String, Object> model = this.getModel(condition, alert);
return this.engine.transform(template, model);
}