This repository has been archived by the owner on Oct 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
add_files_to_healthbot.py
93 lines (69 loc) · 3.57 KB
/
add_files_to_healthbot.py
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
############################################################################################################################
# This script add to heathbot the files located to the directories: rules, playbooks, tables_and_views, functions,
############################################################################################################################
############################################################################################################################
# requirements: pip install requests
############################################################################################################################
############################################################################################################################
# usage:
# ls rules
# ls playbooks
# ls tables_and_views
# ls functions
# vi add_files_to_healthbot.py
# python ./add_files_to_healthbot.py
############################################################################################################################
import os
import yaml
import requests
from requests.auth import HTTPBasicAuth
from requests.packages.urllib3.exceptions import InsecureRequestWarning
def add_tables_and_views(file_name):
files = {'up_file': open('tables_and_views/' + file_name,'r')}
r=requests.post(url + '/files/helper-files/' + file_name, auth=HTTPBasicAuth(authuser, authpwd), headers={ 'Accept' : 'application/json' }, verify=False, files=files)
print file_name
return r.status_code
def add_function(file_name):
files = {'up_file': open('functions/' + file_name,'r')}
r=requests.post(url + '/files/helper-files/' + file_name, auth=HTTPBasicAuth(authuser, authpwd), headers={ 'Accept' : 'application/json' }, verify=False, files=files)
print file_name
return r.status_code
def add_rule(file_name):
files = {'topics': open('rules/' + file_name,'r')}
r=requests.post(url + '/topics/', auth=HTTPBasicAuth(authuser, authpwd), headers={ 'Accept' : 'application/json'}, verify=False, files=files)
print file_name
return r.status_code
def add_playbook(file_name):
files = {'playbooks': open('playbooks/' + file_name,'r')}
r=requests.post(url + '/playbooks/', auth=HTTPBasicAuth(authuser, authpwd), headers={ 'Accept' : 'application/json' }, verify=False, files=files)
print file_name
return r.status_code
def commit():
r = requests.post(url + '/configuration', auth=HTTPBasicAuth(authuser, authpwd), headers=headers, verify=False)
print 'healthbot configuration commited!'
return r.status_code
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# update this section with your healthbot ip address
server = "100.123.35.0"
authuser = "jcluser"
authpwd = "Juniper!1"
url = 'https://'+ server + ':8080/api/v1'
headers = { 'Accept' : 'application/json', 'Content-Type' : 'application/json' }
rules_list=os.listdir('rules')
playbooks_list=os.listdir('playbooks')
tables_and_views_list=os.listdir('tables_and_views')
functions_list=os.listdir('functions')
print '**************** adding tables and views ************************'
for table in tables_and_views_list:
add_tables_and_views(table)
print '**************** adding functions ************************'
for function in functions_list:
add_function(function)
print '**************** adding rules ************************'
for rule in rules_list:
add_rule(rule)
print '**************** adding playbooks ************************'
for playbook in playbooks_list:
add_playbook(playbook)
print '**************** committing changeset **********************'
commit()