Пример #1
0
func xmlcheck(golog syslog.Writer, provider string, phone string, data []byte) {

	//	log.Println("GetUrl:xmlcheck check provider ", provider, "phone", phone)
	//
	//	<SmsResponse>
	//        <version>1</version>
	//        <result>1</result>
	//        <resultstring>success</resultstring>
	//        <description></description>
	//        <partcount>1</partcount>
	//        <endcause></endcause>
	//</SmsResponse>

	v := Dataxml{}
	err := xml.Unmarshal(data, &v)
	if err != nil {
		//		fmt.Printf("error: %v", err)
		golog.Err(err.Error())

		blockphone(phone)

	} else {

		//		fmt.Printf("Result: %q\n", v.Result)
		golog.Info(v.Result)

	}
}
Пример #2
0
func configParse(cfg *config, mainLogger *syslog.Writer) bool {
	const KEY = 0
	const VAL = 1
	file, err := os.Open(CONFIG_PATH)
	if err != nil {
		return false
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)
	newConf := false
	for scanner.Scan() {
		read := scanner.Text()
		if len(read) > 0 && read[0] != '#' {
			newConf = true
			pair := strings.Split(read, "=")
			trimmedKey := strings.TrimSpace(pair[KEY])
			trimmedVal := strings.TrimSpace(pair[VAL])
			val, _ := strconv.Atoi(trimmedVal)
			configUpdate(cfg, trimmedKey, uint16(val))
			mainLogger.Info(fmt.Sprintf("Custom setting found %s: %s", trimmedKey, trimmedVal))
		}
	}

	if !newConf {
		mainLogger.Info("No custom settings found, using defaults")
	}

	if err := scanner.Err(); err != nil {
		log.Fatal("Error: could not parse config file")
	}

	return true
}
Пример #3
0
func SendSMS(golog syslog.Writer, clphonenum string, text string, site string) {

	var smsout d.Smsout

	if text == "" {

		golog.Info("Send first SMS on " + clphonenum)
		smsout.Phoneto = strings.Replace(clphonenum, "358", "0", 1)
		smsout.Text = "Soita! Miia. puh. 070095943"
		smsout.Phonefrom = "070095943"
		smsout.Opcode = "notImpotent"
		smsout.Nmake = "notImpotent"

	} else {
		golog.Info("Send Second SMS on " + clphonenum + " " + text)

		smsout.Phoneto = strings.Replace(clphonenum, "358", "0", 1)
		smsout.Text = text
		smsout.Phonefrom = "070095943"
		smsout.Opcode = "notImpotent"
		smsout.Nmake = "notImpotent"

	}

	pr.SmsSendBy("sonera", smsout, golog)

}
Пример #4
0
func sendToSyslog(message *nats.Msg, syslog *syslog.Writer) {
	logMessage := buildLogMessage(message)
	logger.Debug("message-sent-to-syslog", lager.Data{"message": logMessage})
	err := syslog.Info(logMessage)
	if err != nil {
		logger.Error("logging-to-syslog-failed", err)
		stop <- true
	}
}
Пример #5
0
func InsertMobileClient(golog syslog.Writer, db sql.DB, sqlstr string) {

	if stmt, err := db.Prepare(sqlstr); err != nil {

		golog.Err(err.Error())

	} else {

		if _, err := stmt.Exec(); err != nil {

			golog.Err(err.Error())

		} else {

			golog.Info("New Client arrived!!!")

		}

	}

}
Пример #6
0
func UpdateAclient(golog syslog.Writer, db sql.DB, sqlstr string) {

	if stmt, err := db.Prepare(sqlstr); err != nil {

		golog.Err(err.Error())

	} else {

		if _, err := stmt.Exec(); err != nil {

			golog.Err(err.Error())

		} else {

			golog.Info("Aclient updated")

		}

	}

}
Пример #7
0
func newSyslogAdapter(w *syslog.Writer) *LoggingAdapter {
	return &LoggingAdapter{
		Debugf: func(format string, v ...interface{}) { w.Debug(fmt.Sprintf(format, v...)) },
		Infof:  func(format string, v ...interface{}) { w.Info(fmt.Sprintf(format, v...)) },
		Warnf:  func(format string, v ...interface{}) { w.Warning(fmt.Sprintf(format, v...)) },
		Errorf: func(format string, v ...interface{}) { w.Err(fmt.Sprintf(format, v...)) },
		Fatalf: func(format string, v ...interface{}) {
			s := fmt.Sprintf(format, v...)

			w.Crit(s)

			os.Exit(1)
		},
		Panicf: func(format string, v ...interface{}) {
			s := fmt.Sprintf(format, v...)

			w.Emerg(s)

			panic(s)
		},
	}
}
Пример #8
0
// Get a list of devices from ring file and virtual mount them using libgfapi
func SetupGlusterDiskFile(serverconf *hummingbird.IniFile, logger *syslog.Writer) (map[string]interface{}, error) {
	hashPathPrefix, hashPathSuffix, _ := hummingbird.GetHashPrefixAndSuffix()
	objRing, _ := hummingbird.GetRing("object", hashPathPrefix, hashPathSuffix)
	bindPort := int(serverconf.GetInt("app:object-server", "bind_port", 6000))
	localDevices, _ := objRing.LocalDevices(bindPort)

	globals := make(map[string]interface{})
	globals["disableFallocate"] = serverconf.GetBool("app:object-server", "disable_fallocate", false)
	globals["glusterVolumes"] = make(map[string]*gfapi.Volume)

	var ret int
	var err error
	for _, dev := range localDevices {
		globals["glusterVolumes"].(map[string]*gfapi.Volume)[dev.Device] = new(gfapi.Volume)

		ret = globals["glusterVolumes"].(map[string]*gfapi.Volume)[dev.Device].Init("localhost", dev.Device)
		if ret < 0 {
			return nil, errors.New(fmt.Sprintf("Volume %s: Init() failed with ret = %d", dev.Device, ret))
		}

		ret, err = globals["glusterVolumes"].(map[string]*gfapi.Volume)[dev.Device].SetLogging("", gfapi.LogDebug)
		if ret < 0 {
			//FIXME: There's a bug in SetLogging: err != nil even when ret = 0
			return nil, errors.New(fmt.Sprintf("Volume %s: SetLogging() failed with ret = %d, error = %s", dev.Device, ret, err.Error()))
		}

		ret = globals["glusterVolumes"].(map[string]*gfapi.Volume)[dev.Device].Mount()
		if ret < 0 {
			return nil, errors.New(fmt.Sprintf("Volume %s: Mount() failed with ret = %d", dev.Device, ret))
		}

		logger.Info(fmt.Sprintf("GlusterFS volume %s sucessfully virtual mounted.", dev.Device))
	}

	return globals, nil
}
Пример #9
0
// Output each metric in the given registry to syslog periodically using
// the given syslogger.  The interval is to be given in seconds.
func Syslog(r Registry, interval int, w *syslog.Writer) {
	for {
		r.Each(func(name string, i interface{}) {
			switch m := i.(type) {
			case Counter:
				w.Info(fmt.Sprintf("counter %s: count: %d", name, m.Count()))
			case Gauge:
				w.Info(fmt.Sprintf("gauge %s: value: %d", name, m.Value()))
			case Healthcheck:
				m.Check()
				w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, m.Error()))
			case Histogram:
				ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
				w.Info(fmt.Sprintf(
					"histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f",
					name,
					m.Count(),
					m.Min(),
					m.Max(),
					m.Mean(),
					m.StdDev(),
					ps[0],
					ps[1],
					ps[2],
					ps[3],
					ps[4],
				))
			case Meter:
				w.Info(fmt.Sprintf(
					"meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f",
					name,
					m.Count(),
					m.Rate1(),
					m.Rate5(),
					m.Rate15(),
					m.RateMean(),
				))
			case Timer:
				ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
				w.Info(fmt.Sprintf(
					"timer %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f",
					name,
					m.Count(),
					m.Min(),
					m.Max(),
					m.Mean(),
					m.StdDev(),
					ps[0],
					ps[1],
					ps[2],
					ps[3],
					ps[4],
					m.Rate1(),
					m.Rate5(),
					m.Rate15(),
					m.RateMean(),
				))
			}
		})
		time.Sleep(time.Duration(int64(1e9) * int64(interval)))
	}
}
Пример #10
0
func SmsSendBy(provider string, smsout d.Smsout, golog syslog.Writer) {

	var urlstr string

	if provider == "elisa" {

		if Url, err := url.Parse("http://localhost:13013"); err != nil {

			panic("boom")
		} else {

			Url.Path += "/cgi-bin/sendsms"
			parameters := url.Values{}
			parameters.Add("username", "elisa")
			parameters.Add("password", "elisa")
			//		parameters.Add("charset", "ISO-8859-1")
			parameters.Add("charset", "UTF8")
			parameters.Add("to", smsout.Phoneto)
			//				parameters.Add("to", "+358504440106") //for test
			//		parameters.Add("from", smsout.Phonefrom)
			parameters.Add("text", smsout.Text)

			Url.RawQuery = parameters.Encode()
			urlstr = Url.String()

		}

	} else if provider == "sonera" {

		if Url, err := url.Parse("http://localhost:8050"); err != nil {

			panic("boom")
		} else {

			Url.Path += "/send"
			parameters := url.Values{}

			parameters.Add("to", smsout.Phoneto)

			parameters.Add("from", strings.Replace(smsout.Phonefrom, "+3587", "07", 1))
			textout := Utf8Conver(smsout.Text, "iso-8859-1")
			parameters.Add("msg", textout)

			Url.RawQuery = parameters.Encode()
			urlstr = Url.String()

		}

	} else if provider == "voicetr" {

		//		log.Println("start voicetr new 11")
		golog.Info("start voicetr")

		if Url, err := url.Parse("https://www.voicetrading.com"); err != nil {

			panic("boom")
		} else {

			Url.Path += "/myaccount/sendsms.php"
			parameters := url.Values{}
			parameters.Add("username", "voicetradingsipvip")
			parameters.Add("password", "164sipviprel")
			//		parameters.Add("charset", "ISO-8859-1")
			parameters.Add("charset", "UTF8")
			parameters.Add("to", smsout.Phoneto)
			//			parameters.Add("to", "+358451202801") /for test
			//							parameters.Add("to", "+358504440106") //for test
			parameters.Add("from", smsout.Phonefrom)
			parameters.Add("text", smsout.Text)

			Url.RawQuery = parameters.Encode()
			urlstr = Url.String()

		}

	} else if provider == "pullpull" {

		if Url, err := url.Parse("http://localhost:13013"); err != nil {

			panic("boom")
		} else {

			if smsout.Opcode == "54" {

				Url.Path += "/cgi-bin/sendsms"
				parameters := url.Values{}
				parameters.Add("username", "dna179029")
				parameters.Add("password", "dna179029")
				//		parameters.Add("charset", "ISO-8859-1")
				parameters.Add("charset", "UTF8")
				parameters.Add("to", smsout.Phoneto)
				parameters.Add("binfo", "2900")
				//				parameters.Add("to", "+358504440106") //for test
				//		parameters.Add("from", smsout.Phonefrom)
				parameters.Add("text", smsout.Text)

				Url.RawQuery = parameters.Encode()
				urlstr = Url.String()

			}

		}
	}
	//	log.Println(urlstr)
	//	fmt.Println(urlstr)
	golog.Info(urlstr)

	GetUrl(golog, provider, smsout.Phoneto, urlstr)

}
Пример #11
0
func Hello(mod *Model, logger *syslog.Writer, version string) string {
	s := fmt.Sprintf("Model=>%v, Version=>%s", mod, version)
	logger.Info(s)
	return s
}
Пример #12
0
func Settasks(makeFlag string, days int, quant int, golog syslog.Writer) {

	quantstr := strconv.Itoa(quant)
	daysstr := strconv.Itoa(days)

	var sqlselectstr string

	if makeFlag == "gsm179019" {
		sqlselectstr = "select * from aclients where (block = 0 and sulje = 0 and ennu = 0 and nmake <> '" + makeFlag + "' and opcode in (50,54,56,49,79,'na') and nupdate_make <=adddate(now(), -" + daysstr + ") and rating>5) or (nmake IS NULL and block = 0 and opcode in (50,54,56,49,79,'na')) order by id desc limit " + quantstr
	}
	if makeFlag == "voicetr" {
		sqlselectstr = "select * from aclients where (block = 0 and sulje = 0 and ennu = 0 and nmake <> '" + makeFlag + "' and opcode in (50,54,56,49,79,'na') and nupdate_make <=adddate(now(), -" + daysstr + ")) or (nmake IS NULL and block = 0 and opcode in (50,54,56,49,79,'na')) order by id desc limit " + quantstr
	}
	if makeFlag == "sms179019" {
		sqlselectstr = "select * from aclients where (block = 0 and sulje = 0 and ennu = 0 and nmake <> '" + makeFlag + "' and opcode in (50,54,56,49,79,'na') and nupdate_make <=adddate(now(), -" + daysstr + ") and smsquant>1) or (nmake IS NULL and block = 0 and opcode in (50,54,56,49,79,'na')) order by id desc limit " + quantstr
	}

	if makeFlag == "sms179029" {
		sqlselectstr = "select * from aclients where (block = 0 and sulje = 0 and ennu = 0 and nmake <> '" + makeFlag + "' and opcode in (54) and nupdate_make <=adddate(now(), -" + daysstr + ") ) or (nmake IS NULL and block = 0 and opcode in (54)) order by id desc limit " + quantstr
	}

	db.Raw.Register("SET NAMES utf8")
	var aclienmap = sql.GetMapAclients(*db, sqlselectstr, makeFlag, golog)

	golog.Info("Ready Settask for " + strconv.Itoa(len(aclienmap)))

	if aclientupdate_stmt, err := db.Prepare("update aclients set nmake = ?,nupdate_make = now() where id = ?"); err != nil {

		golog.Err(err.Error())

	} else {

		for _, Aclient := range aclienmap {

			fmt.Println(Aclient.Phone)
			fmt.Println(Aclient.Opcode)
			fmt.Println(Aclient.Nmake)
			fmt.Println("---------")

			if _, _, err := aclientupdate_stmt.Exec(makeFlag, Aclient.Id); err != nil {
				golog.Err(err.Error())
			}

		}

		jsbyte, _ := json.Marshal(aclienmap)

		buff := bytes.NewBuffer(jsbyte)

		client := &http.Client{}

		if req, err := http.NewRequest("POST", "http://latest.kannelgo.sinelgamysql.appspot.com/settasks", buff); err != nil {

			fmt.Printf("Error: %v\n", err)

		} else {

			req.Header.Add("makeFlag", makeFlag)

			if resp, err1 := client.Do(req); err1 != nil {
				fmt.Printf("Error: %v\n", err1)
			} else {
				defer resp.Body.Close()
				body, _ := ioutil.ReadAll(resp.Body)
				fmt.Println("Body: %s\n", body)
			}

		}

	}

}
Пример #13
0
func Gettasks(makeFlag string, quant int, golog syslog.Writer) {

	golog.Info("Start Gettasks")

	quantstr := strconv.Itoa(quant)

	if res, err := http.Get("http://latest.kannelgo.sinelgamysql.appspot.com/gettasks?makeflag=" + makeFlag + "&tasksquant=" + quantstr); err != nil {

		golog.Err(err.Error())

	} else {

		if data, err := ioutil.ReadAll(res.Body); err != nil {

			golog.Err(err.Error())

		} else {

			sliceforjson := make([]d.Smsout, 2)

			json.Unmarshal(data, &sliceforjson)

			var sendok bool
			for _, smsout := range sliceforjson {

				sendok = false
				golog.Info(smsout.Phoneto)
				golog.Info(smsout.Opcode)
				golog.Info(smsout.Nmake)

				sendok = checkaclient.CheckByPhone(smsout.Phoneto)

				if sendok {

					golog.Info("sendok OK makeFlag " + makeFlag)

					if makeFlag == "sms179019" {

						//					pr.SendSMSKannel(smsout)
						// for now elisa
						pr.SmsSendBy("elisa", smsout, golog)
						//					pr.SendSMSCgwSonera(smsout)
						//					pr.SendSMSSonera(smsout)

					} else if makeFlag == "gsm179019" {
						//					pr.SendSMSSonera(smsout)
						pr.SmsSendBy("sonera", smsout, golog)
						//					pr.SendSMSCgwSonera(smsout) //problems öä

					} else if makeFlag == "voicetr" {

						golog.Info("send by vocetr")
						pr.SmsSendBy("voicetr", smsout, golog)

					} else if makeFlag == "sms179029" {

						golog.Info("send by pullpull now DNA only")
						pr.SmsSendBy("pullpull", smsout, golog)

					}

					insertsmsins.InsertSmsRecord(smsout.Phoneto, smsout.Text, makeFlag, golog)

				} else {

					//					fmt.Println("Dont't send sms for "+smsout.Phoneto)
					golog.Warning("Dont't send sms for " + smsout.Phoneto)
				}
			}

		}
	}
}
Пример #14
0
// Output each metric in the given registry to syslog periodically using
// the given syslogger.
func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
	for _ = range time.Tick(d) {
		r.Each(func(name string, i interface{}) {
			switch metric := i.(type) {
			case Counter:
				w.Info(fmt.Sprintf("counter %s: count: %d", name, metric.Count()))
			case Gauge:
				w.Info(fmt.Sprintf("gauge %s: value: %d", name, metric.Value()))
			case GaugeFloat64:
				w.Info(fmt.Sprintf("gauge %s: value: %f", name, metric.Value()))
			case Healthcheck:
				metric.Check()
				w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, metric.Error()))
			case Histogram:
				h := metric.Snapshot()
				ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
				w.Info(fmt.Sprintf(
					"histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f",
					name,
					h.Count(),
					h.Min(),
					h.Max(),
					h.Mean(),
					h.StdDev(),
					ps[0],
					ps[1],
					ps[2],
					ps[3],
					ps[4],
				))
			case Meter:
				m := metric.Snapshot()
				w.Info(fmt.Sprintf(
					"meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f",
					name,
					m.Count(),
					m.Rate1(),
					m.Rate5(),
					m.Rate15(),
					m.RateMean(),
				))
			case Timer:
				t := metric.Snapshot()
				ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
				w.Info(fmt.Sprintf(
					"timer %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f 1-min: %.2f 5-min: %.2f 15-min: %.2f mean-rate: %.2f",
					name,
					t.Count(),
					t.Min(),
					t.Max(),
					t.Mean(),
					t.StdDev(),
					ps[0],
					ps[1],
					ps[2],
					ps[3],
					ps[4],
					t.Rate1(),
					t.Rate5(),
					t.Rate15(),
					t.RateMean(),
				))
			}
		})
	}
}