forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/ add vms/email debt notification (labring#4763)
* optimize debt log & fix named kb cluster backup pvc named. * add vms notification for debt * add email notification for debt
- Loading branch information
Showing
21 changed files
with
1,308 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright © 2024 sealos. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package utils | ||
|
||
import "github.com/go-gomail/gomail" | ||
|
||
type SMTPConfig struct { | ||
ServerHost string | ||
ServerPort int | ||
FromEmail string | ||
Passwd string | ||
EmailTitle string | ||
} | ||
|
||
func (c *SMTPConfig) SendEmail(emailBody, to string) error { | ||
m := gomail.NewMessage() | ||
m.SetHeader("To", to) | ||
m.SetAddressHeader("From", c.FromEmail, c.EmailTitle) | ||
m.SetHeader("Subject", c.EmailTitle) | ||
m.SetBody("text/html", emailBody) | ||
d := gomail.NewDialer(c.ServerHost, c.ServerPort, c.FromEmail, c.Passwd) | ||
return d.DialAndSend(m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright © 2024 sealos. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/astaxie/beego/logs" | ||
"github.com/volcengine/volc-sdk-golang/service/vms" | ||
) | ||
|
||
func SendVms(phone, template, numberPollNo string, sendTime time.Time, forbidTimes []string) error { | ||
var paramList []*vms.SingleParam | ||
paramList = append(paramList, &vms.SingleParam{ | ||
Phone: phone, | ||
Type: 1, | ||
//RingAgainTimes: 1, | ||
//RingAgainInterval: 5, | ||
TriggerTime: &vms.JsonTime{Time: sendTime}, | ||
Resource: template, | ||
NumberPoolNo: numberPollNo, | ||
SingleOpenId: phone + "-" + sendTime.Format("2006-01-02"), | ||
}) | ||
if len(forbidTimes) != 0 { | ||
paramList[0].ForbidTimeList = []*vms.ForbidTimeItem{ | ||
{ | ||
Times: forbidTimes, | ||
}, | ||
} | ||
} | ||
req := &vms.SingleAppendRequest{ | ||
List: paramList, | ||
} | ||
result, statusCode, err := vms.DefaultInstance.SingleBatchAppend(req) | ||
if err != nil { | ||
return fmt.Errorf("failed to SingleBatchAppend: %v", err) | ||
} | ||
if result.ResponseMetadata.Error != nil { | ||
return fmt.Errorf("failed to send vms: %v", result.ResponseMetadata.Error) | ||
} | ||
logs.Info("send vms status code: %d, result: %#+v", statusCode, result.Result) | ||
if statusCode != 200 { | ||
return fmt.Errorf("failed to send vms, status code: %d, err : %v", statusCode, result) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright © 2024 sealos. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package utils | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/volcengine/volc-sdk-golang/service/vms" | ||
) | ||
|
||
func TestSendVms(t *testing.T) { | ||
vms.DefaultInstance.Client.SetAccessKey(os.Getenv("VMS_AK")) | ||
vms.DefaultInstance.Client.SetSecretKey(os.Getenv("VMS_SK")) | ||
var testData = struct { | ||
phone string | ||
template string | ||
numberPollNo string | ||
sendTime time.Time | ||
}{ | ||
phone: "", | ||
template: "", | ||
numberPollNo: "", | ||
sendTime: time.Now(), | ||
} | ||
err := SendVms(testData.phone, testData.template, testData.numberPollNo, testData.sendTime, []string{"10:00-20:00"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Log("SendVms success") | ||
} |
Oops, something went wrong.