├── g ├── g.go └── cfg.go ├── cron ├── init.go ├── sms.go └── mail.go ├── http ├── proc.go ├── common.go └── http.go ├── proc └── proc.go ├── NOTICE ├── .gitignore ├── cfg.example.json ├── model └── model.go ├── redis ├── redis.go └── pop.go ├── README.md ├── main.go ├── control └── LICENSE /g/g.go: -------------------------------------------------------------------------------- 1 | package g 2 | 3 | import ( 4 | "log" 5 | "runtime" 6 | ) 7 | 8 | const ( 9 | VERSION = "0.0.0" 10 | ) 11 | 12 | func init() { 13 | runtime.GOMAXPROCS(runtime.NumCPU()) 14 | log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) 15 | } 16 | -------------------------------------------------------------------------------- /cron/init.go: -------------------------------------------------------------------------------- 1 | package cron 2 | 3 | import ( 4 | "github.com/open-falcon/sender/g" 5 | ) 6 | 7 | var ( 8 | SmsWorkerChan chan int 9 | MailWorkerChan chan int 10 | ) 11 | 12 | func InitWorker() { 13 | workerConfig := g.Config().Worker 14 | SmsWorkerChan = make(chan int, workerConfig.Sms) 15 | MailWorkerChan = make(chan int, workerConfig.Mail) 16 | } 17 | -------------------------------------------------------------------------------- /http/proc.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "fmt" 5 | "github.com/open-falcon/sender/proc" 6 | "net/http" 7 | ) 8 | 9 | func configProcRoutes() { 10 | 11 | http.HandleFunc("/count", func(w http.ResponseWriter, r *http.Request) { 12 | w.Write([]byte(fmt.Sprintf("sms:%v, mail:%v", proc.GetSmsCount(), proc.GetMailCount()))) 13 | }) 14 | 15 | } 16 | -------------------------------------------------------------------------------- /proc/proc.go: -------------------------------------------------------------------------------- 1 | package proc 2 | 3 | import ( 4 | "sync/atomic" 5 | ) 6 | 7 | var smsCount, mailCount uint32 8 | 9 | func GetSmsCount() uint32 { 10 | return atomic.LoadUint32(&smsCount) 11 | } 12 | 13 | func GetMailCount() uint32 { 14 | return atomic.LoadUint32(&mailCount) 15 | } 16 | 17 | func IncreSmsCount() { 18 | atomic.AddUint32(&smsCount, 1) 19 | } 20 | 21 | func IncreMailCount() { 22 | atomic.AddUint32(&mailCount, 1) 23 | } 24 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Open-Falcon 2 | 3 | Copyright (c) 2014-2015 Xiaomi, Inc. All Rights Reserved. 4 | 5 | This product is licensed to you under the Apache License, Version 2.0 (the "License"). 6 | You may not use this product except in compliance with the License. 7 | 8 | This product may include a number of subcomponents with separate copyright notices 9 | and license terms. Your use of these subcomponents is subject to the terms and 10 | conditions of the subcomponent's license, as noted in the LICENSE file. 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | *.swp 27 | *.swo 28 | *.log 29 | .idea 30 | .DS_Store 31 | /var 32 | /falcon-sender* 33 | /sender* 34 | /cfg.json 35 | /gitversion 36 | 37 | -------------------------------------------------------------------------------- /cfg.example.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": true, 3 | "http": { 4 | "enabled": true, 5 | "listen": "0.0.0.0:6066" 6 | }, 7 | "redis": { 8 | "addr": "127.0.0.1:6379", 9 | "maxIdle": 5 10 | }, 11 | "queue": { 12 | "sms": "/sms", 13 | "mail": "/mail" 14 | }, 15 | "worker": { 16 | "sms": 10, 17 | "mail": 50 18 | }, 19 | "api": { 20 | "sms": "http://11.11.11.11:8000/sms", 21 | "mail": "http://11.11.11.11:9000/mail" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /model/model.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type Sms struct { 8 | Tos string `json:"tos"` 9 | Content string `json:"content"` 10 | } 11 | 12 | type Mail struct { 13 | Tos string `json:"tos"` 14 | Subject string `json:"subject"` 15 | Content string `json:"content"` 16 | } 17 | 18 | func (this *Sms) String() string { 19 | return fmt.Sprintf( 20 | "", 21 | this.Tos, 22 | this.Content, 23 | ) 24 | } 25 | 26 | func (this *Mail) String() string { 27 | return fmt.Sprintf( 28 | "", 29 | this.Tos, 30 | this.Subject, 31 | this.Content, 32 | ) 33 | } 34 | -------------------------------------------------------------------------------- /redis/redis.go: -------------------------------------------------------------------------------- 1 | package redis 2 | 3 | import ( 4 | "github.com/garyburd/redigo/redis" 5 | "github.com/open-falcon/sender/g" 6 | "log" 7 | "time" 8 | ) 9 | 10 | var ConnPool *redis.Pool 11 | 12 | func InitConnPool() { 13 | redisConfig := g.Config().Redis 14 | 15 | ConnPool = &redis.Pool{ 16 | MaxIdle: redisConfig.MaxIdle, 17 | IdleTimeout: 240 * time.Second, 18 | Dial: func() (redis.Conn, error) { 19 | c, err := redis.Dial("tcp", redisConfig.Addr) 20 | if err != nil { 21 | return nil, err 22 | } 23 | return c, err 24 | }, 25 | TestOnBorrow: PingRedis, 26 | } 27 | } 28 | 29 | func PingRedis(c redis.Conn, t time.Time) error { 30 | _, err := c.Do("ping") 31 | if err != nil { 32 | log.Println("[ERROR] ping redis fail", err) 33 | } 34 | return err 35 | } 36 | -------------------------------------------------------------------------------- /http/common.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "github.com/open-falcon/sender/g" 5 | "github.com/toolkits/file" 6 | "net/http" 7 | "strings" 8 | ) 9 | 10 | func configCommonRoutes() { 11 | http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { 12 | w.Write([]byte("ok")) 13 | }) 14 | 15 | http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { 16 | w.Write([]byte(g.VERSION)) 17 | }) 18 | 19 | http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) { 20 | RenderDataJson(w, file.SelfDir()) 21 | }) 22 | 23 | http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) { 24 | if strings.HasPrefix(r.RemoteAddr, "127.0.0.1") { 25 | g.ParseConfig(g.ConfigFile) 26 | RenderDataJson(w, g.Config()) 27 | } else { 28 | w.Write([]byte("no privilege")) 29 | } 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | falcon-sender 2 | ============= 3 | 4 | alarm处理报警event可能会产生报警短信或者报警邮件,alarm不负责发送,只是把报警邮件、短信写入redis队列,sender负责读取并发 5 | 送。 6 | 7 | 各个公司有自己的短信通道,自己的邮件发送方式,sender如何调用各个公司自己的组件呢?那只能制定规范了,sender的配置文件 8 | cfg.json中配置了api:sms和api:mail,即两个http接口,这是需要各个公司提供的。 9 | 10 | 当要发送短信的时候,sender就会调用api:sms中配置的http接口,post方式,参数是: 11 | 12 | - tos:用逗号分隔的多个手机号 13 | - content:短信内容 14 | 15 | 当要发送邮件的时候,sender就会调用api:mail中配置的http接口,post方式,参数是: 16 | 17 | - tos:用逗号分隔的多个邮箱地址 18 | - content:邮件正文 19 | - subject:邮件标题 20 | 21 | ## Installation 22 | 23 | ```bash 24 | # set $GOPATH and $GOROOT 25 | mkdir -p $GOPATH/src/github.com/open-falcon 26 | cd $GOPATH/src/github.com/open-falcon 27 | git clone https://github.com/open-falcon/sender.git 28 | cd sender 29 | go get ./... 30 | ./control build 31 | # vi cfg.json modify configuration 32 | ./control start 33 | ``` 34 | 35 | ## Configuration 36 | 37 | - redis: redis地址需要和alarm、judge使用同一个 38 | - queue: 维持默认即可,需要和alarm的配置一致 39 | - worker: 最多同时有多少个线程玩命得调用短信、邮件发送接口 40 | - api: 短信、邮件发送的http接口,各公司自己提供 41 | 42 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/open-falcon/sender/cron" 7 | "github.com/open-falcon/sender/g" 8 | "github.com/open-falcon/sender/http" 9 | "github.com/open-falcon/sender/redis" 10 | "os" 11 | "os/signal" 12 | "syscall" 13 | ) 14 | 15 | func main() { 16 | cfg := flag.String("c", "cfg.json", "configuration file") 17 | version := flag.Bool("v", false, "show version") 18 | help := flag.Bool("h", false, "help") 19 | flag.Parse() 20 | 21 | if *version { 22 | fmt.Println(g.VERSION) 23 | os.Exit(0) 24 | } 25 | 26 | if *help { 27 | flag.Usage() 28 | os.Exit(0) 29 | } 30 | 31 | g.ParseConfig(*cfg) 32 | cron.InitWorker() 33 | redis.InitConnPool() 34 | 35 | go http.Start() 36 | go cron.ConsumeSms() 37 | go cron.ConsumeMail() 38 | 39 | sigs := make(chan os.Signal, 1) 40 | signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) 41 | go func() { 42 | <-sigs 43 | fmt.Println() 44 | redis.ConnPool.Close() 45 | os.Exit(0) 46 | }() 47 | 48 | select {} 49 | } 50 | -------------------------------------------------------------------------------- /cron/sms.go: -------------------------------------------------------------------------------- 1 | package cron 2 | 3 | import ( 4 | "github.com/open-falcon/sender/g" 5 | "github.com/open-falcon/sender/model" 6 | "github.com/open-falcon/sender/proc" 7 | "github.com/open-falcon/sender/redis" 8 | "github.com/toolkits/net/httplib" 9 | "log" 10 | "time" 11 | ) 12 | 13 | func ConsumeSms() { 14 | queue := g.Config().Queue.Sms 15 | for { 16 | L := redis.PopAllSms(queue) 17 | if len(L) == 0 { 18 | time.Sleep(time.Millisecond * 200) 19 | continue 20 | } 21 | SendSmsList(L) 22 | } 23 | } 24 | 25 | func SendSmsList(L []*model.Sms) { 26 | for _, sms := range L { 27 | SmsWorkerChan <- 1 28 | go SendSms(sms) 29 | } 30 | } 31 | 32 | func SendSms(sms *model.Sms) { 33 | defer func() { 34 | <-SmsWorkerChan 35 | }() 36 | 37 | url := g.Config().Api.Sms 38 | r := httplib.Post(url).SetTimeout(5*time.Second, 2*time.Minute) 39 | r.Param("tos", sms.Tos) 40 | r.Param("content", sms.Content) 41 | resp, err := r.String() 42 | if err != nil { 43 | log.Println(err) 44 | } 45 | 46 | proc.IncreSmsCount() 47 | 48 | if g.Config().Debug { 49 | log.Println("==sms==>>>>", sms) 50 | log.Println("<<<<==sms==", resp) 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /cron/mail.go: -------------------------------------------------------------------------------- 1 | package cron 2 | 3 | import ( 4 | "github.com/open-falcon/sender/g" 5 | "github.com/open-falcon/sender/model" 6 | "github.com/open-falcon/sender/proc" 7 | "github.com/open-falcon/sender/redis" 8 | "github.com/toolkits/net/httplib" 9 | "log" 10 | "time" 11 | ) 12 | 13 | func ConsumeMail() { 14 | queue := g.Config().Queue.Mail 15 | for { 16 | L := redis.PopAllMail(queue) 17 | if len(L) == 0 { 18 | time.Sleep(time.Millisecond * 200) 19 | continue 20 | } 21 | SendMailList(L) 22 | } 23 | } 24 | 25 | func SendMailList(L []*model.Mail) { 26 | for _, mail := range L { 27 | MailWorkerChan <- 1 28 | go SendMail(mail) 29 | } 30 | } 31 | 32 | func SendMail(mail *model.Mail) { 33 | defer func() { 34 | <-MailWorkerChan 35 | }() 36 | 37 | url := g.Config().Api.Mail 38 | r := httplib.Post(url).SetTimeout(5*time.Second, 2*time.Minute) 39 | r.Param("tos", mail.Tos) 40 | r.Param("subject", mail.Subject) 41 | r.Param("content", mail.Content) 42 | resp, err := r.String() 43 | if err != nil { 44 | log.Println(err) 45 | } 46 | 47 | proc.IncreMailCount() 48 | 49 | if g.Config().Debug { 50 | log.Println("==mail==>>>>", mail) 51 | log.Println("<<<<==mail==", resp) 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /redis/pop.go: -------------------------------------------------------------------------------- 1 | package redis 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/garyburd/redigo/redis" 6 | "github.com/open-falcon/sender/model" 7 | "log" 8 | ) 9 | 10 | func PopAllSms(queue string) []*model.Sms { 11 | ret := []*model.Sms{} 12 | 13 | rc := ConnPool.Get() 14 | defer rc.Close() 15 | 16 | for { 17 | reply, err := redis.String(rc.Do("RPOP", queue)) 18 | if err != nil { 19 | if err != redis.ErrNil { 20 | log.Println(err) 21 | } 22 | break 23 | } 24 | 25 | if reply == "" || reply == "nil" { 26 | continue 27 | } 28 | 29 | var sms model.Sms 30 | err = json.Unmarshal([]byte(reply), &sms) 31 | if err != nil { 32 | log.Println(err, reply) 33 | continue 34 | } 35 | 36 | ret = append(ret, &sms) 37 | } 38 | 39 | return ret 40 | } 41 | 42 | func PopAllMail(queue string) []*model.Mail { 43 | ret := []*model.Mail{} 44 | 45 | rc := ConnPool.Get() 46 | defer rc.Close() 47 | 48 | for { 49 | reply, err := redis.String(rc.Do("RPOP", queue)) 50 | if err != nil { 51 | if err != redis.ErrNil { 52 | log.Println(err) 53 | } 54 | break 55 | } 56 | 57 | if reply == "" || reply == "nil" { 58 | continue 59 | } 60 | 61 | var mail model.Mail 62 | err = json.Unmarshal([]byte(reply), &mail) 63 | if err != nil { 64 | log.Println(err, reply) 65 | continue 66 | } 67 | 68 | ret = append(ret, &mail) 69 | } 70 | 71 | return ret 72 | } 73 | -------------------------------------------------------------------------------- /http/http.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/open-falcon/sender/g" 6 | "log" 7 | "net/http" 8 | _ "net/http/pprof" 9 | ) 10 | 11 | type Dto struct { 12 | Msg string `json:"msg"` 13 | Data interface{} `json:"data"` 14 | } 15 | 16 | func init() { 17 | configCommonRoutes() 18 | configProcRoutes() 19 | } 20 | 21 | func RenderJson(w http.ResponseWriter, v interface{}) { 22 | bs, err := json.Marshal(v) 23 | if err != nil { 24 | http.Error(w, err.Error(), http.StatusInternalServerError) 25 | return 26 | } 27 | w.Header().Set("Content-Type", "application/json; charset=UTF-8") 28 | w.Write(bs) 29 | } 30 | 31 | func RenderDataJson(w http.ResponseWriter, data interface{}) { 32 | RenderJson(w, Dto{Msg: "success", Data: data}) 33 | } 34 | 35 | func RenderMsgJson(w http.ResponseWriter, msg string) { 36 | RenderJson(w, map[string]string{"msg": msg}) 37 | } 38 | 39 | func AutoRender(w http.ResponseWriter, data interface{}, err error) { 40 | if err != nil { 41 | RenderMsgJson(w, err.Error()) 42 | return 43 | } 44 | RenderDataJson(w, data) 45 | } 46 | 47 | func Start() { 48 | if !g.Config().Http.Enabled { 49 | return 50 | } 51 | 52 | addr := g.Config().Http.Listen 53 | if addr == "" { 54 | return 55 | } 56 | s := &http.Server{ 57 | Addr: addr, 58 | MaxHeaderBytes: 1 << 30, 59 | } 60 | log.Println("http listening", addr) 61 | log.Fatalln(s.ListenAndServe()) 62 | } 63 | -------------------------------------------------------------------------------- /g/cfg.go: -------------------------------------------------------------------------------- 1 | package g 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/toolkits/file" 6 | "log" 7 | "sync" 8 | ) 9 | 10 | type HttpConfig struct { 11 | Enabled bool `json:"enabled"` 12 | Listen string `json:"listen"` 13 | } 14 | 15 | type RedisConfig struct { 16 | Addr string `json:"addr"` 17 | MaxIdle int `json:"maxIdle"` 18 | } 19 | 20 | type QueueConfig struct { 21 | Sms string `json:"sms"` 22 | Mail string `json:"mail"` 23 | } 24 | 25 | type WorkerConfig struct { 26 | Sms int `json:"sms"` 27 | Mail int `json:"mail"` 28 | } 29 | 30 | type ApiConfig struct { 31 | Sms string `json:"sms"` 32 | Mail string `json:"mail"` 33 | } 34 | 35 | type GlobalConfig struct { 36 | Debug bool `json:"debug"` 37 | Http *HttpConfig `json:"http"` 38 | Redis *RedisConfig `json:"redis"` 39 | Queue *QueueConfig `json:"queue"` 40 | Worker *WorkerConfig `json:"worker"` 41 | Api *ApiConfig `json:"api"` 42 | } 43 | 44 | var ( 45 | ConfigFile string 46 | config *GlobalConfig 47 | configLock = new(sync.RWMutex) 48 | ) 49 | 50 | func Config() *GlobalConfig { 51 | configLock.RLock() 52 | defer configLock.RUnlock() 53 | return config 54 | } 55 | 56 | func ParseConfig(cfg string) { 57 | if cfg == "" { 58 | log.Fatalln("use -c to specify configuration file") 59 | } 60 | 61 | if !file.IsExist(cfg) { 62 | log.Fatalln("config file:", cfg, "is not existent") 63 | } 64 | 65 | ConfigFile = cfg 66 | 67 | configContent, err := file.ToTrimString(cfg) 68 | if err != nil { 69 | log.Fatalln("read config file:", cfg, "fail:", err) 70 | } 71 | 72 | var c GlobalConfig 73 | err = json.Unmarshal([]byte(configContent), &c) 74 | if err != nil { 75 | log.Fatalln("parse config file:", cfg, "fail:", err) 76 | } 77 | 78 | configLock.Lock() 79 | defer configLock.Unlock() 80 | config = &c 81 | log.Println("read config file:", cfg, "successfully") 82 | } 83 | -------------------------------------------------------------------------------- /control: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WORKSPACE=$(cd $(dirname $0)/; pwd) 4 | cd $WORKSPACE 5 | 6 | mkdir -p var 7 | 8 | module=sender 9 | app=falcon-$module 10 | conf=cfg.json 11 | pidfile=var/app.pid 12 | logfile=var/app.log 13 | 14 | function check_pid() { 15 | if [ -f $pidfile ];then 16 | pid=`cat $pidfile` 17 | if [ -n $pid ]; then 18 | running=`ps -p $pid|grep -v "PID TTY" |wc -l` 19 | return $running 20 | fi 21 | fi 22 | return 0 23 | } 24 | 25 | function start() { 26 | check_pid 27 | running=$? 28 | if [ $running -gt 0 ];then 29 | echo -n "$app now is running already, pid=" 30 | cat $pidfile 31 | return 1 32 | fi 33 | 34 | nohup ./$app -c $conf >> $logfile 2>&1 & 35 | echo $! > $pidfile 36 | echo "$app started..., pid=$!" 37 | } 38 | 39 | function stop() { 40 | pid=`cat $pidfile` 41 | kill $pid 42 | echo "$app stoped..." 43 | } 44 | 45 | function restart() { 46 | stop 47 | sleep 1 48 | start 49 | } 50 | 51 | function status() { 52 | check_pid 53 | running=$? 54 | if [ $running -gt 0 ];then 55 | echo -n "$app now is running, pid=" 56 | cat $pidfile 57 | else 58 | echo "$app is stoped" 59 | fi 60 | } 61 | 62 | function tailf() { 63 | tail -f $logfile 64 | } 65 | 66 | function build() { 67 | go build 68 | if [ $? -ne 0 ]; then 69 | exit $? 70 | fi 71 | mv $module $app 72 | ./$app -v 73 | } 74 | 75 | function pack() { 76 | build 77 | git log -1 --pretty=%h > gitversion 78 | version=`./$app -v` 79 | tar zcvf $app-$version.tar.gz control cfg.example.json $app gitversion 80 | } 81 | 82 | function packbin() { 83 | build 84 | git log -1 --pretty=%h > gitversion 85 | version=`./$app -v` 86 | tar zcvf $app-bin-$version.tar.gz $app gitversion 87 | } 88 | 89 | function help() { 90 | echo "$0 build|pack|packbin|start|stop|restart|status|tail" 91 | } 92 | 93 | if [ "$1" == "" ]; then 94 | help 95 | elif [ "$1" == "stop" ];then 96 | stop 97 | elif [ "$1" == "start" ];then 98 | start 99 | elif [ "$1" == "restart" ];then 100 | restart 101 | elif [ "$1" == "status" ];then 102 | status 103 | elif [ "$1" == "tail" ];then 104 | tailf 105 | elif [ "$1" == "build" ];then 106 | build 107 | elif [ "$1" == "pack" ];then 108 | pack 109 | elif [ "$1" == "packbin" ];then 110 | packbin 111 | else 112 | help 113 | fi 114 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------