-
Notifications
You must be signed in to change notification settings - Fork 206
/
servicenow-source.sh
executable file
·99 lines (82 loc) · 3.5 KB
/
servicenow-source.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
#!/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"
TODAY=$(date -u '+%Y-%m-%d')
log "Creating ServiceNow Source connector"
playground connector create-or-update --connector servicenow-source << EOF
{
"connector.class": "io.confluent.connect.servicenow.ServiceNowSourceConnector",
"kafka.topic": "topic-servicenow",
"servicenow.url": "$SERVICENOW_URL",
"tasks.max": "1",
"servicenow.table": "incident",
"servicenow.user": "admin",
"servicenow.password": "$SERVICENOW_PASSWORD",
"servicenow.since": "$TODAY",
"key.converter": "org.apache.kafka.connect.json.JsonConverter",
"value.converter": "org.apache.kafka.connect.json.JsonConverter",
"confluent.license": "",
"confluent.topic.bootstrap.servers": "broker:9092",
"confluent.topic.replication.factor": "1"
}
EOF
sleep 10
log "Create one record to ServiceNow"
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"}'
sleep 5
log "Verify we have received the data in topic-servicenow topic"
playground topic consume --topic topic-servicenow --min-expected-messages 1 --timeout 60