-
Notifications
You must be signed in to change notification settings - Fork 208
/
Copy pathservicenow-sink.sh
executable file
·129 lines (113 loc) · 4.46 KB
/
servicenow-sink.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source ${DIR}/../../scripts/utils.sh
function wait_for_end_of_hibernation () {
MAX_WAIT=600
CUR_WAIT=0
set +e
log "⌛ Waiting up to $MAX_WAIT seconds for end of hibernation to happen (it can take several minutes)"
curl -X POST "${SERVICENOW_URL}/api/now/table/incident" --user admin:"$SERVICENOW_PASSWORD" -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d '{"short_description": "This is test"}' > /tmp/out.txt 2>&1
while [[ $(cat /tmp/out.txt) =~ "Sign in to the site to wake your instance" ]]
do
sleep 10
curl -X POST "${SERVICENOW_URL}/api/now/table/incident" --user admin:"$SERVICENOW_PASSWORD" -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d '{"short_description": "This is test"}' > /tmp/out.txt 2>&1
CUR_WAIT=$(( CUR_WAIT+10 ))
if [[ "$CUR_WAIT" -gt "$MAX_WAIT" ]]; then
echo -e "\nERROR: The logs still show 'Sign in to the site to wake your instance' after $MAX_WAIT seconds.\n"
exit 1
fi
done
log "The instance is ready !"
set -e
}
SERVICENOW_URL=${SERVICENOW_URL:-$1}
SERVICENOW_PASSWORD=${SERVICENOW_PASSWORD:-$2}
if [ -z "$SERVICENOW_URL" ]
then
logerror "SERVICENOW_URL is not set. Export it as environment variable or pass it as argument"
exit 1
fi
if [[ "$SERVICENOW_URL" != */ ]]
then
logerror "SERVICENOW_URL does not end with "/" Example: https://dev12345.service-now.com/ "
exit 1
fi
if [ -z "$SERVICENOW_PASSWORD" ]
then
logerror "SERVICENOW_PASSWORD is not set. Export it as environment variable or pass it as argument"
exit 1
fi
if [ ! -z "$GITHUB_RUN_NUMBER" ]
then
# this is github actions
set +e
log "Waking up servicenow instance..."
docker run -e USERNAME="$SERVICENOW_DEVELOPER_USERNAME" -e PASSWORD="$SERVICENOW_DEVELOPER_PASSWORD" vdesabou/servicenowinstancewakeup:latest
set -e
wait_for_end_of_hibernation
fi
PLAYGROUND_ENVIRONMENT=${PLAYGROUND_ENVIRONMENT:-"plaintext"}
playground start-environment --environment "${PLAYGROUND_ENVIRONMENT}" --docker-compose-override-file "${PWD}/docker-compose.plaintext.yml"
log "Sending messages to topic test_table"
playground topic produce -t test_table --nb-messages 3 << 'EOF'
{
"fields": [
{
"name": "u_name",
"type": "string"
},
{
"name": "u_price",
"type": "float"
},
{
"name": "u_quantity",
"type": "int"
}
],
"name": "myrecord",
"type": "record"
}
EOF
log "Creating ServiceNow Sink connector"
playground connector create-or-update --connector servicenow-sink << EOF
{
"connector.class": "io.confluent.connect.servicenow.ServiceNowSinkConnector",
"topics": "test_table",
"servicenow.url": "$SERVICENOW_URL",
"tasks.max": "1",
"servicenow.table": "u_test_table",
"servicenow.user": "admin",
"servicenow.password": "$SERVICENOW_PASSWORD",
"key.converter": "io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url": "http://schema-registry:8081",
"value.converter": "io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url": "http://schema-registry:8081",
"reporter.bootstrap.servers": "broker:9092",
"reporter.error.topic.name": "test-error",
"reporter.error.topic.replication.factor": 1,
"reporter.error.topic.key.format": "string",
"reporter.error.topic.value.format": "string",
"reporter.result.topic.name": "test-result",
"reporter.result.topic.key.format": "string",
"reporter.result.topic.value.format": "string",
"reporter.result.topic.replication.factor": 1,
"confluent.license": "",
"confluent.topic.bootstrap.servers": "broker:9092",
"confluent.topic.replication.factor": "1"
}
EOF
sleep 15
log "Verifying topic test-result"
playground topic consume --topic test-result --min-expected-messages 3 --timeout 60
playground topic consume --topic test-error --min-expected-messages 0 --timeout 60
log "Confirm that the messages were delivered to the ServiceNow table"
curl -X GET \
"${SERVICENOW_URL}/api/now/table/u_test_table" \
--user admin:"$SERVICENOW_PASSWORD" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' | jq . > /tmp/result.log 2>&1
cat /tmp/result.log
grep "u_name" /tmp/result.log