-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-host-opsview.bash
executable file
·77 lines (72 loc) · 1.99 KB
/
add-host-opsview.bash
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
#!/bin/bash
USERNAME_OPS="USERNAME"
PASSWORD_OPS="PASSWORD"
OPSVIEW_URL="http://opsview.foo.bar"
HOSTFILE=`tempfile`
HOSTNAME=`hostname --fqdn | tr '[:lower:]' '[:upper:]'`
IP_PUBLIC=`curl --silent ifconfig.me`
CURL=`which curl`
TOKEN=`$CURL --silent -d '{"username":"'$USERNAME_OPS'","password":"'$PASSWORD_OPS'"}' -H "Content-Type: application/json" -H "Accept: application/json" $OPSVIEW_URL/rest/login | cut -d: -f2 | cut -d} -f1 | cut -d'"' -f2`
cat > $HOSTFILE << EOF
{
"name": "$HOSTNAME",
"ip": "$IP_PUBLIC",
"hostgroup": {
"name": "HOSTGROUP",
},
"hosttemplates": [
{
"name": "OS - Linux Base"
} ],
"check_period": [
{
"name" : "24x7"
}
],
"hostattributes": [
{
"arg2": null,
"arg1": null,
"arg4": null,
"value": "/dev/vda1",
"arg3": null,
"name": "DISK"},
{
"arg2": null,
"arg1": null,
"arg4": null,
"value": "/dev/vda2",
"arg3": null,
"name": "DISK"},
{
"arg2": null,
"arg1": null,
"arg4": null,
"value": "eth0",
"arg3": null,
"name": "LAN_INTERFACE"},
{
"arg2": null,
"arg1": null,
"arg4": null,
"value": "lo",
"arg3": null,
"name": "LAN_INTERFACE"}],
"notification_period" : {
"ref" : "/rest/config/timeperiod/1",
"name" : "24x7"
},
"notification_options": "u,d,r",
"notification_interval": "5",
"icon" :
{
"name" : "LOGO - centos"
},
"check_command" :
{
"ref" : "/rest/config/hostcheckcommand/17",
"name" : "NRPE SSH"}
}
EOF
$CURL --silent -H "Accept: application/json" -H "X-Opsview-Username: $USERNAME_OPS" -H "X-Opsview-Token: $TOKEN" -H "Content-Type: application/json" -X PUT -d "@$HOSTFILE" $OPSVIEW_URL/rest/config/host
$CURL --silent -H "Accept: application/json" -H "X-Opsview-Username: $USERNAME_OPS" -H "X-Opsview-Token: $TOKEN" -H "Content-Type: application/json" -X POST $OPSVIEW_URL/rest/reload