open-falcon SMS alarm

Now I use Xiaomi's open-falcon at work, and the preparation is OK. Now I want to report the alarm through SMS, but I found the official website and only provides an alarm mail-provider about emails, and there is no SMS. Researched for a while. Finally got it.

First of all, my operating environment is CentOS6.5. The order of building open-falcon in the early stage is based on the official documentation, so I won't mention it again.

One of the important modules for SMS sending is the sender module.
Official website link: http://book.open-falcon.org/zh/install_from_src/sender.html
sender module configuration file cfg.json

{
    "debug": true,
    "http": {
        "enabled": true,
        "listen ": "0.0.0.0:6066"
    },
    "redis": {
        "addr": "127.0.0.1:6379", # The redis address configured here should be configured with the same
        "maxIdle" as the following judge and alarm: 5
    },
    "queue": {
        "sms": "/sms",
        "mail": "/mail" # Mail queue name, keep the default, there will be a same configuration in alarm
    },
    "worker": {
        "sms": 10, # The maximum concurrency of calling the SMS interface
        "mail ": 50 # The maximum number of concurrent calls to the mail interface
    },
    "api": {
        "sms": "http://192.168.1.101:8080/sms/sms/send", # SMS address is its own HTTP SMS service interface
        "mail": "http://11.11.11.11:9000/mail" # You can write your email address
    }
}

What is the SMS interface? To put it bluntly, it is to use tomcat to open an interface service of the http protocol.

I just took one of my MVC projects and made a copy:

package com.sms.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

/**
 * Handles requests for the application home page.
 */
@Controller
@RequestMapping("/sms")
public class HomeController {

	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@ResponseBody
	@RequestMapping("/send")
	public String sendStr(String content,String tos) {
		StringBuffer sb = new StringBuffer();
		sb.append(content.split("]")[2].replace("[", ""));
		sb.append(content.split("]")[4].split(" ")[0].replace("[", ""));
		sb.append(content.split("]")[5].split(" ")[2].split(":")[0]);
		sb.append(":");
		sb.append(content.split("]")[5].split(" ")[2].split(":")[1]);
		String url = "Ali's SMS API";
		String appkey = "Ali's appkey, please register yourself";
		String secret = "Ali's secret, please register yourself";
		TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
		AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
		req.setExtend("123456");
		req.setSmsType("normal");
		req.setSmsFreeSignName("Test Signature");
		req.setSmsParamString("{\"name\":\"XXXX\",\"message\":\""+sb.toString()+"\"}");
		req.setRecNum(tos);
		req.setSmsTemplateCode("Ali's SMS text message module number");
		AlibabaAliqinFcSmsNumSendResponse rsp;
		try {
			rsp = client.execute(req);
			System.out.println(rsp.getBody());
			return rsp.getBody();
		} catch (ApiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace ();
		}
		return "";
	}
}


I use Ali's SMS API to write. have nothing to say. The specific process is that the Agent collects information and transmits it to Transfer. The Transfer is in two copies, which are respectively passed to the graph for subsequent processing of the graph,
and then passed to the Judge for the alarm judgment. The alarm task is sent to the redis queue, and the Alarm module obtains it from the redis queue, and then processes whether to send a text message or an email according to the alarm event. Sending a text message is to call the sms api configured in cfg.json in the sender module.
Here comes the point: But when you look at the api of cfg.json in the sender module, you will find that the api service written in the official website demo is just a URL but no parameters, right? You may ask, how did his parameters come over? In fact, when I call the api of cfg.json, I bring the parameters by default. The two parameters in my java code method above must be written, and he will assign values ​​unknowingly when calling the api. !
For example:
content parameter (warning content): "[P0][PROBLEM][g-09][][ all(#1) mem.memfree.percent 64.28836<=100][O1 2016-11-27 09:31 :00]" This is the same as the warning message of the Alarm module in the web! .

tos parameter (phone number sent by SMS): This is actually the phone number of the user in the bound group user group when you configure the Portal policy.


Haha, you know? In fact, as long as you have an http interface, the sender is configured, and the user's mobile phone number bound to the Portal policy is filled in, it's OK, don't worry about other things! Of course, the configuration files of other modules should also be configured well, and each module should see ./control tail! OK, it's over!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326983359&siteId=291194637