-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshinken-api.py
629 lines (536 loc) · 24.6 KB
/
shinken-api.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
import os
import socket
import platform
import glob
import re
import time
try:
import paramiko
except:
print ("DryRun for test only this module : parmaiko is not installed")
from flask.helpers import make_response
try:
import dbus
except:
print ("DryRun test Linux ,only this module dbus : does not exist on Windows")
import random
from flask import Flask, redirect, url_for, request, render_template
from flask import jsonify
from flasgger import Swagger
#from pymongo import MongoClient
"""
This function will detect and ip range and return a list of ip :
ex : 10.0.0.1-10.0.0.3
10.0.0.1
10.0.0.2
10.0.0.3
"""
def ipRange(start_ip, end_ip):
start = list(map(int, start_ip.split(".")))
end = list(map(int, end_ip.split(".")))
temp = start
ip_range = []
ip_range.append(start_ip)
while temp != end:
start[3] += 1
for i in (3, 2, 1):
if temp[i] == 256:
temp[i] = 0
temp[i-1] += 1
ip_range.append(".".join(map(str, temp)))
return ip_range
"""
This function will detect hosts range and return a list of ip
ex : range web00[1-3]-dev
web001
web002
web003
"""
def hostRange(hostrange):
# dsdciits19[702-711]v-int
p = re.compile('\[(.*)\]')
number = p.findall(hostrange)
range_number = number[0].split("-")
range_number = map(int, range_number)
start = range_number[0]
end = range_number[1]
host_list = []
while start <= end:
host_list.append(p.sub(str(start), hostrange))
start += 1
return host_list
"""
This function will check for the host ip from dns or local entries :
Same as lookup command
"""
def lookup_ip(addr):
try:
return socket.gethostbyaddr(addr)
except socket.herror:
return None, None, None
"""
This function will check for the host from dns or local entries :
Same as lookup command
"""
def lookup_host(host):
try:
return socket.gethostbyname(host)
except socket.gaierror:
return None
"""
This function will check if the host respond to ssh protocol
"""
def check_ssh(ip, user, key_file, initial_wait=0, interval=0, retries=1):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
time.sleep(initial_wait)
for x in range(retries):
try:
ssh.connect(ip, username=user, key_filename=key_file)
return True
#except (BadHostKeyException, AuthenticationException, SSHException, socket.error) as e:
except:
#print e
time.sleep(interval)
return False
app = Flask(__name__)
Swagger(app)
@app.route('/<string:version>/shinken/<string:action>', methods=['GET'])
def controle_shinken_(action,version):
"""
This is the language awesomeness API
Call this api passing a language name and get back its features
---
tags:
- Awesomeness Language API
parameters:
- name: language
in: path
type: string
required: true
description: The language name
- name: size
in: query
type: integer
description: size of awesomeness
responses:
500:
description: Error The language is not awesome!
200:
description: A language with its awesomeness
schema:
id: awesome
properties:
language:
type: string
description: The language name
default: Lua
features:
type: array
description: The awesomeness list
items:
type: string
default: ["perfect", "simple", "lovely"]
"""
output = []
if action == 'restart' and version.lower() == 'v3':
sysbus = dbus.SystemBus()
systemd1 = sysbus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
manager = dbus.Interface(systemd1, 'org.freedesktop.systemd1.Manager')
job = manager.RestartUnit('shinken-arbiter.service', 'fail')
output.append({'Shinken' : "Shinken restarted" })
elif action == 'stop':
sysbus = dbus.SystemBus()
systemd1 = sysbus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
manager = dbus.Interface(systemd1, 'org.freedesktop.systemd1.Manager')
job = manager.StopUnit('shinken-arbiter.service', 'fail')
output.append({'Shinken' : "Shinken stopped" })
elif action == 'start':
sysbus = dbus.SystemBus()
systemd1 = sysbus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
manager = dbus.Interface(systemd1, 'org.freedesktop.systemd1.Manager')
job = manager.StartUnit('shinken-arbiter.service', 'fail')
output.append({'Shinken' : "Shinken started" })
else:
output.append({ 'id' : 'SHNK-002', 'Message' : 'Unknow Action please use : /v3/shinken/Action = [start | restart | stop ]'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 404)
return response
return jsonify({'Notification' : output })
@app.route('/<string:version>/hosts', methods=['POST'])
def add_host(version):
# star = db.shinken_config
contact_groups = request.json['contact_groups']
hostgroups = request.json['hostgroups']
_SSH_KEY = request.json['_SSH_KEY']
_SSH_USER = request.json['_SSH_USER']
output = []
if 'host_name' in request.json and 'address' in request.json and 'use' in request.json:
host_name = request.json['host_name']
address = request.json['address']
use = request.json['use']
host_name = host_name.replace(" ", "")
address = address.replace(" ", "")
use = use.replace(" ", "")
if use and host_name and address:
if check_ssh(address, _SSH_USER, _SSH_KEY):
output = {'use' : use, 'contact_groups': contact_groups, 'host_name' : host_name, 'address' : address, 'hostgroups' : hostgroups, '_SSH_KEY' : _SSH_KEY, '_SSH_USER' : _SSH_USER}
# write to file
f = open('/etc/shinken/hosts/' + host_name + '.cfg' , 'w+')
# modele f.write( 'dict = ' + repr(dict) + '\n' )
f.write('define host {\n\tuse\t\t\t\t' + use + '\n\tcontact_groups\t\t\t' + contact_groups + '\t\n\thost_name\t\t\t' + host_name + '\n\taddress\t\t\t\t' + address + '\n\thostgroups\t\t\t' + hostgroups + '\n\t_SSH_KEY\t\t\t' + _SSH_KEY + '\n\t_SSH_USER\t\t\t' + _SSH_USER + '\n}\n')
f.close()
#f.seek(0,0)
#for index in range(6):
# line = f.next()
# print "Line No %d - %s" % (index, line)
# Close opend file
#f.close()
sysbus = dbus.SystemBus()
systemd1 = sysbus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
manager = dbus.Interface(systemd1, 'org.freedesktop.systemd1.Manager')
job = manager.RestartUnit('shinken-arbiter.service', 'fail')
#return jsonify({'define host' : output})
response = make_response(jsonify({'define host' : output }), 201)
return response
else:
output.append({ 'id' : 'SHNK-006', 'Message' : 'HOST unreachable through ssh'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
else:
output.append({ 'id' : 'SHNK-003', 'Message' : 'Value can not be empty or a space'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
else:
output.append({ 'id' : 'SHNK-001', 'Message' : 'Missing requeried field : Please note that "use" and "host_name" and "address" are mandatory '})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
@app.route('/<string:version>/hostsbyiprl', methods=['POST'])
def add_host_by_ip_range(version):
contact_groups = request.json['contact_groups']
hostgroups = request.json['hostgroups']
_SSH_KEY = request.json['_SSH_KEY']
_SSH_USER = request.json['_SSH_USER']
output = []
if 'address_range' in request.json and 'use' in request.json:
address_range = request.json['address_range']
use = request.json['use']
address_range = address_range.replace(" ", "")
use = use.replace(" ", "")
if use and address_range:
if "-" in address_range:
#172.27.87.184-172.27.87.184
# sample usage
ip_range = ipRange(str(address_range.split('-')[0]) , str(address_range.split('-')[1]))
for ip in ip_range:
#print(ip)
print (str(address_range.split('-')[0]))
print (str(address_range.split('-')[1]))
name,alias,addresslist = lookup_ip(ip)
if not name:
output.append({ 'id' : 'SHNK-005', 'Message' : 'No host is matching the ' + ip })
continue
elif not check_ssh(ip, _SSH_USER, _SSH_KEY):
output.append({ 'id' : 'SHNK-006', 'Message' : 'HOST unreachable through ssh'})
continue
else:
host_name = name.split('.')[0]
address = ip
output.append({'use' : use, 'contact_groups': contact_groups, 'host_name' : host_name, 'address' : address, 'hostgroups' : hostgroups, '_SSH_KEY' : _SSH_KEY, '_SSH_USER' : _SSH_USER})
# write to file
f = open('/etc/shinken/hosts/' + host_name + '.cfg' , 'w+')
# modele f.write( 'dict = ' + repr(dict) + '\n' )
f.write('define host {\n\tuse\t\t\t\t' + use + '\n\tcontact_groups\t\t\t' + contact_groups + '\t\n\thost_name\t\t\t' + host_name + '\n\taddress\t\t\t\t' + address + '\n\thostgroups\t\t\t' + hostgroups + '\n\t_SSH_KEY\t\t\t' + _SSH_KEY + '\n\t_SSH_USER\t\t\t' + _SSH_USER + '\n}\n')
f.close()
#return jsonify({'define host' : output"})
response = make_response(jsonify({'define host' : output }), 201)
return response
elif "," in address_range:
#for list 172.27.87.184,172.27.87.184
ip_range = address_range.split(',')
for ip in ip_range:
#print(ip)
name,alias,addresslist = lookup_ip(ip)
if not name:
output.append({ 'id' : 'SHNK-005', 'Message' : 'No host is matching the ' + ip })
continue
elif not check_ssh(ip, _SSH_USER, _SSH_KEY):
output.append({ 'id' : 'SHNK-006', 'Message' : 'HOST unreachable through ssh'})
continue
else:
host_name = name.split('.')[0]
address = ip
output.append({'use' : use, 'contact_groups': contact_groups, 'host_name' : host_name, 'address' : address, 'hostgroups' : hostgroups, '_SSH_KEY' : _SSH_KEY, '_SSH_USER' : _SSH_USER})
# write to file
f = open('/etc/shinken/hosts/' + host_name + '.cfg' , 'w+')
# modele f.write( 'dict = ' + repr(dict) + '\n' )
f.write('define host {\n\tuse\t\t\t\t' + use + '\n\tcontact_groups\t\t\t' + contact_groups + '\t\n\thost_name\t\t\t' + host_name + '\n\taddress\t\t\t\t' + address + '\n\thostgroups\t\t\t' + hostgroups + '\n\t_SSH_KEY\t\t\t' + _SSH_KEY + '\n\t_SSH_USER\t\t\t' + _SSH_USER + '\n}\n')
f.close()
#return jsonify({'define host' : output"})
response = make_response(jsonify({'define host' : output }), 201)
return response
else:
output.append({ 'id' : 'SHNK-004', 'Message' : 'Unknown range format'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
else:
output.append({ 'id' : 'SHNK-003', 'Message' : 'Value can not be empty or a space'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
else:
output.append({ 'id' : 'SHNK-001', 'Message' : 'Missing requeried field : Please note that "use" and "host_name" and "address" are mandatory '})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
@app.route('/<string:version>/hostsbyhostr', methods=['POST'])
def add_host_by_host_range(version):
contact_groups = request.json['contact_groups']
hostgroups = request.json['hostgroups']
_SSH_KEY = request.json['_SSH_KEY']
_SSH_USER = request.json['_SSH_USER']
output = []
if 'host_range' in request.json and 'use' in request.json:
host_range = request.json['host_range']
use = request.json['use']
host_range = host_range.replace(" ", "")
use = use.replace(" ", "")
if use and host_range:
if "-" in host_range and "[" in host_range and "]" in host_range:
#172.27.87.184-172.27.87.184
# sample usage
# add function
host_list = hostRange(host_range)
for host in host_list:
#print(ip)
ip = lookup_host(host)
if not ip:
output.append({ 'id' : 'SHNK-005', 'Message' : 'No ip is matching the ' + host })
continue
elif not check_ssh(ip, _SSH_USER, _SSH_KEY):
output.append({ 'id' : 'SHNK-006', 'Message' : 'HOST unreachable through ssh'})
continue
else:
address = ip
host_name = host
output.append({'use' : use, 'contact_groups': contact_groups, 'host_name' : host_name, 'address' : address, 'hostgroups' : hostgroups, '_SSH_KEY' : _SSH_KEY, '_SSH_USER' : _SSH_USER})
# write to file
f = open('/etc/shinken/hosts/' + host_name + '.cfg' , 'w+')
# modele f.write( 'dict = ' + repr(dict) + '\n' )
f.write('define host {\n\tuse\t\t\t\t' + use + '\n\tcontact_groups\t\t\t' + contact_groups + '\t\n\thost_name\t\t\t' + host_name + '\n\taddress\t\t\t\t' + address + '\n\thostgroups\t\t\t' + hostgroups + '\n\t_SSH_KEY\t\t\t' + _SSH_KEY + '\n\t_SSH_USER\t\t\t' + _SSH_USER + '\n}\n')
f.close()
#return jsonify({'define host' : output"})
response = make_response(jsonify({'define host' : output }), 201)
return response
elif "," in host_range:
#for list 172.27.87.184,172.27.87.184
host_list = host_range.split(',')
for host in host_list:
#print(ip)
ip = lookup_host(host)
if not ip:
output.append({ 'id' : 'SHNK-005', 'Message' : 'No ip is matching the ' + host })
continue
elif not check_ssh(ip, _SSH_USER, _SSH_KEY):
output.append({ 'id' : 'SHNK-006', 'Message' : 'HOST unreachable through ssh'})
continue
else:
address = ip
host_name = host
output.append({'use' : use, 'contact_groups': contact_groups, 'host_name' : host_name, 'address' : address, 'hostgroups' : hostgroups, '_SSH_KEY' : _SSH_KEY, '_SSH_USER' : _SSH_USER})
# write to file
f = open('/etc/shinken/hosts/' + host_name + '.cfg' , 'w+')
# modele f.write( 'dict = ' + repr(dict) + '\n' )
f.write('define host {\n\tuse\t\t\t\t' + use + '\n\tcontact_groups\t\t\t' + contact_groups + '\t\n\thost_name\t\t\t' + host_name + '\n\taddress\t\t\t\t' + address + '\n\thostgroups\t\t\t' + hostgroups + '\n\t_SSH_KEY\t\t\t' + _SSH_KEY + '\n\t_SSH_USER\t\t\t' + _SSH_USER + '\n}\n')
f.close()
response = make_response(jsonify({'define host' : output }), 201)
return response
else:
output.append({ 'id' : 'SHNK-004', 'Message' : 'Unknown range format'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
else:
output.append({ 'id' : 'SHNK-003', 'Message' : 'Value can not be empty or a space'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
else:
output.append({ 'id' : 'SHNK-001', 'Message' : 'Missing requeried field : Please note that "use" and "host_name" and "address" are mandatory '})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
@app.route('/<string:version>/hosts/search/<string:name>', methods=['GET'])
def get_one_host_by_name(name,version):
output = []
for fic in glob.glob("/etc/shinken/hosts/*.cfg"):
with open(fic) as f:
contents = f.read()
if name in contents:
print (fic)
output.append({'File' : fic , 'content' : contents.replace('\n',' ').replace('\t',' ') })
return jsonify({'Result' : output })
@app.route('/<string:version>/hosts/deletematch/<string:name>', methods=['GET'])
def remove_host_by_name(name,version):
output = []
for fic in glob.glob("/etc/shinken/hosts/*.cfg"):
with open(fic) as f:
contents = f.read()
if name in contents:
print (fic)
output.append(fic)
# Remove all matched files
if len(output) == 1:
for fic2remove in output:
# /!\ risk to remove all config
os.remove(fic2remove)
else:
output.append({'Error' : 'Too many files to be deleted use ' + request.path + '/force to complete this operation', 'count' : len(output) })
response = make_response(jsonify({'Error' : output }), 409)
return response
return jsonify({'Deleted files' : output })
@app.route('/<string:version>/hosts/deletematch/<string:name>/force', methods=['GET'])
def remove_force_multiple_host_by_name(name,version):
output = []
for fic in glob.glob("/etc/shinken/hosts/*.cfg"):
with open(fic) as f:
contents = f.read()
if name in contents:
print (fic)
output.append(fic)
# Remove all matched files
#if len(output) == 1:
for fic2remove in output:
# /!\ risk to remove all config
os.remove(fic2remove)
#else:
# output.append({'Error' : 'Too many files'})
# return jsonify({'Error' : output })
return jsonify({'Deleted files' : output })
@app.route('/<string:version>/hosts', methods=['GET'])
def seeking_for_hosts_by_name(version):
output = set()
for fic in glob.glob("/etc/shinken/hosts/*.cfg"):
with open(fic) as f:
for line in f:
if 'host_name' in line:
output.add(line.split('\t\t\t')[1].strip())
output = list(output)
#return jsonify({'Hosts' : output , 'count' : len(output) })
response = make_response(jsonify({'Hosts' : output , 'count' : len(output) }), 404)
return response
@app.route('/<string:version>/packs', methods=['GET'])
def seeking_for_packs_by_name(version):
output = set()
#output = []
for fic in glob.glob("/etc/shinken/hosts/*.cfg"):
with open(fic) as f:
for line in f:
if 'use' in line:
line = line.replace('use','').replace('\t', '').strip()
# if ',' in line:
#line_without_comma = line.split('\t\t\t')[1].strip()
#print line_without_comma.split(",")
#output |= set(line_without_comma.split(","))
output |= set(line.split(","))
#else:
#output.add(line.split('\t\t\t')[1].strip())
output = list(output)
return jsonify({'Packs' : output , 'count' : len(output) })
@app.route('/<string:version>/hostgroups', methods=['GET'])
def seeking_for_hostgroupe_by_name(version):
output = set()
for fic in glob.glob("/etc/shinken/hosts/*.cfg"):
with open(fic) as f:
for line in f:
if 'hostgroups' in line:
output.add(line.split('\t\t\t')[1].strip())
output = list(output)
return jsonify({'Hostgroups' : output , 'count' : len(output) })
##
### Dependencies Block
##
@app.route('/<string:version>/hostsdependencies', methods=['POST'])
def add_hosts_dependencies_(version):
# New block
output = []
if 'host_name' in request.json and 'dependent_host_name' in request.json:
host_name = request.json['host_name']
dependent_host_name = request.json['dependent_host_name']
host_name = host_name.replace(" ", "")
dependent_host_name = dependent_host_name.replace(" ", "")
if host_name and dependent_host_name:
output = {'host_name' : host_name, 'dependent_host_name': dependent_host_name, 'execution_failure_criteria' : 'o', 'notification_failure_criteria' : 'u', 'dependency_period' : '24x7'}
# write to file
f = open('/etc/shinken/dependencies/' + host_name + '-' + dependent_host_name + '.cfg' , 'w+')
# modele f.write( 'dict = ' + repr(dict) + '\n' )
f.write('define hostdependency {\n\thost_name\t\t\t\t' + host_name + '\n\tdependent_host_name\t\t\t' + dependent_host_name + '\n\texecution_failure_criteria\t\t\to\n\tnotification_failure_criteria\t\t\tu\n\tdependency_period\t\t\t24x7\n}\n')
f.close()
response = make_response(jsonify({'define host' : output }), 201)
return response
else:
output.append({ 'id' : 'SHNK-003', 'Message' : 'Value can not be empty or a space'})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
else:
output.append({ 'id' : 'SHNK-001', 'Message' : 'Missing requeried field : Please note that "host_name" and "dependent_host_name" are mandatory '})
#return jsonify({ 'Error' : output })
response = make_response(jsonify({'Error' : output }), 417)
return response
#
@app.route('/<string:version>/dependencies/search/<string:name>', methods=['GET'])
def get_one_depencencies_by_name(name,version):
output = []
for fic in glob.glob("/etc/shinken/dependencies/*.cfg"):
with open(fic) as f:
contents = f.read()
if name in contents:
print (fic)
output.append({'File' : fic , 'content' : contents.replace('\n',' ').replace('\t',' ') })
return jsonify({'Dependencies' : output , 'count' : len(output) })
@app.route('/<string:version>/dependencies/deletematch/<string:name>', methods=['GET'])
def remove_hostdependencies_by_name(name,version):
output = []
for fic in glob.glob("/etc/shinken/dependencies/*.cfg"):
with open(fic) as f:
contents = f.read()
if name in contents:
print (fic)
output.append(fic)
# Remove all matched files
if len(output) == 1:
for fic2remove in output:
# /!\ risk to remove all config
os.remove(fic2remove)
else:
output.append({'Error' : 'Too many files to be deleted use ' + request.path + '/force to complete this operation', 'count' : len(output) })
return jsonify({'Error' : output })
return jsonify({'Deleted files' : output })
@app.route('/<string:version>/dependencies/deletematch/<string:name>/force', methods=['GET'])
def remove_force_multiple_hostdependencies_by_name(name,version):
output = []
for fic in glob.glob("/etc/shinken/dependencies/*.cfg"):
with open(fic) as f:
contents = f.read()
if name in contents:
print (fic)
output.append(fic)
# Remove all matched files
#if len(output) == 1:
for fic2remove in output:
# /!\ risk to remove all config
os.remove(fic2remove)
#else:
# output.append({'Error' : 'Too many files to be deleted', 'count' : len(output) })
# return jsonify({'Error' : output })
return jsonify({'Deleted Dependencies' : output })
if __name__ == "__main__":
if platform.system() == "Linux":
app.run(host='0.0.0.0',port=5000, debug=True)
elif platform.system() == "Windows":
app.run(host='0.0.0.0',port=50000, debug=True)