Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ outputs:
enable: false
user: # Mandatory. E.g :johndoe@gmail.com"
password: # Mandatory. Specify user API key
instance: # Mandatory. Name of ServiceN ow Instance
url: # Mandatory. ServiceNow instance URL (e.g. https://ven05031.service-now.com/ or https://fsadev.servicenowservices.com)
board: # Specify the ServiceNow board name to open tickets on. Default is "incident"

2 changes: 1 addition & 1 deletion deploy/kubernetes/postee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data:
enable: false
user: xxxxxxxxx
password: xxxxxxxxxx
instance: xxxxxxxx
url: https://your-instance.service-now.com/
- type: slack
name: my-slack
enable: false
Expand Down
23 changes: 12 additions & 11 deletions outputs/servicenow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

"github.com/pkg/errors"
Expand All @@ -23,7 +24,7 @@ type ServiceNowOutput struct {
Name string
User string
Password string
Instance string
Url string // ServiceNow instance URL (e.g. https://ven05031.service-now.com/ or https://fsadev.servicenowservices.com)
Table string
layoutProvider layout.LayoutProvider
}
Expand All @@ -38,21 +39,20 @@ func (sn *ServiceNowOutput) GetName() string {

func (sn *ServiceNowOutput) CloneSettings() *data.OutputSettings {
return &data.OutputSettings{
Name: sn.Name,
User: sn.User,
//password
InstanceName: sn.Instance,
BoardName: sn.Table,
Enable: true,
Type: serviceNowType,
Name: sn.Name,
User: sn.User,
Url: sn.Url,
BoardName: sn.Table,
Enable: true,
Type: serviceNowType,
}
}

func (sn *ServiceNowOutput) Init() error {
sn.layoutProvider = new(formatting.HtmlProvider)

log.Logger.Infof("Successfully initialized ServiceNow output %q", sn.Name)
log.Logger.Debugf("Your ServiceNow Table is %q on '%s.%s'", sn.Table, sn.Instance, servicenow.BaseServer)
log.Logger.Debugf("Your ServiceNow Table is %q at %q", sn.Table, sn.Url)
return nil
}

Expand Down Expand Up @@ -90,13 +90,14 @@ func (sn *ServiceNowOutput) Send(content map[string]string) (data.OutputResponse
return data.OutputResponse{}, errors.New("Error when trying to parse ServiceNow integration data")
}

resp, err := servicenow.InsertRecordToTable(sn.User, sn.Password, sn.Instance, sn.Table, body)
resp, err := servicenow.InsertRecordToTable(sn.User, sn.Password, sn.Url, sn.Table, body)
if err != nil {
log.Logger.Error("ServiceNow Error: ", err)
return data.OutputResponse{}, errors.New("Failed inserting record to the ServiceNow table")
}

ticketLink := fmt.Sprintf("https://%s.service-now.com/nav_to.do?uri=%s.do?sys_id=%s", sn.Instance, sn.Table, resp.SysID)
baseURL := strings.TrimSuffix(sn.Url, "/")
ticketLink := fmt.Sprintf("%s/nav_to.do?uri=%s.do?sys_id=%s", baseURL, sn.Table, resp.SysID)
log.Logger.Infof("Successfully sent a message via ServiceNow %q, ID %q, Link %q", sn.Name, resp.SysID, ticketLink)
return data.OutputResponse{Key: resp.SysID, Url: ticketLink, Name: sn.Name}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion router/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func buildServiceNow(sourceSettings *data.OutputSettings) *outputs.ServiceNowOut
Name: sourceSettings.Name,
User: sourceSettings.User,
Password: sourceSettings.Password,
Url: sourceSettings.Url,
Table: sourceSettings.BoardName,
Instance: sourceSettings.InstanceName,
}
if len(serviceNow.Table) == 0 {
serviceNow.Table = ServiceNowTableDefault
Expand Down
14 changes: 7 additions & 7 deletions router/initoutputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ func TestBuildAndInitOtpt(t *testing.T) {
{
"Simple ServiceNow output",
data.OutputSettings{
Name: "my-servicenow",
Type: "serviceNow",
User: "admin",
Password: "secret",
InstanceName: "dev108148",
BoardName: "incindent",
Name: "my-servicenow",
Type: "serviceNow",
User: "admin",
Password: "secret",
Url: "https://dev108148.service-now.com/",
BoardName: "incindent",
},
map[string]interface{}{
"User": "admin",
"Password": "secret",
"Instance": "dev108148",
"Url": "https://dev108148.service-now.com/",
"Table": "incindent",
},
false,
Expand Down
10 changes: 7 additions & 3 deletions servicenow/insert_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strings"

"github.com/aquasecurity/postee/v2/utils"
)

func InsertRecordToTable(user, password, instance, table string, content []byte) (*ServiceNowResponse, error) {
url := fmt.Sprintf("https://%s.%s%s%s%s",
instance, BaseServer, baseApiUrl, tableApi, table)
// InsertRecordToTable posts a record to the given ServiceNow table.
// instanceURL is the ServiceNow instance root URL (e.g. "https://ven05031.service-now.com/" or "https://fsadev.servicenowservices.com"),
// as provided by the customer; it is not constructed from instance name + baseServer.
func InsertRecordToTable(user, password, instanceURL, table string, content []byte) (*ServiceNowResponse, error) {
base := strings.TrimSuffix(instanceURL, "/")
url := base + "/" + baseApiPath + table
r := bytes.NewReader(content)
client := http.DefaultClient
reg, err := http.NewRequest("POST", url, r)
Expand Down
4 changes: 1 addition & 3 deletions servicenow/servicenow_base.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package servicenow_api

const (
BaseServer = "service-now.com/"
baseApiUrl = "api/now/"
tableApi = "table/"
baseApiPath = "api/now/table/"
)

type ServiceNowData struct {
Expand Down
15 changes: 2 additions & 13 deletions ui/frontend/src/components/OutputDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -362,19 +362,7 @@

<!-- jira custom properties end -->
<!-- serviceNow custom properties start -->
<div class="row">
<div class="col">
<PropertyField
id="instance"
label="Instance"
:value="formValues.instance"
description="Mandatory. Name of ServiceNow or Instance"
:errorMsg="errors['instance']"
:show="isServiceNow"
:inputHandler="updateField"
:validator="v(required)"
/>
</div>
<div class="row" v-if="isServiceNow">
<div class="col">
<PropertyField
id="board"
Expand Down Expand Up @@ -434,6 +422,7 @@ const urlDescriptionByType = {
teams: "Webhook's url",
jira: 'Mandatory. E.g "https://johndoe.atlassian.net"',
slack: "",
serviceNow: "ServiceNow instance URL (e.g. https://ven05031.service-now.com/ or https://fsadev.servicenowservices.com)",
};
const typesWithCredentials = ["serviceNow", "email"]; //TODO add description strings

Expand Down
Loading