@click.option('--threshold_value', prompt=True,
help='threshold value that, when crossed, an alarm is triggered')
@click.option('--threshold_operator', prompt=True,
- help='threshold operator describing the comparison (GE, LE, GT, LT, EQ')
+ help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
@click.option('--statistic', default='AVERAGE',
help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
@click.pass_context
def ns_alarm_create(ctx, name, ns, vnf, vdu, metric, severity,
threshold_value, threshold_operator, statistic):
'''creates a new alarm for a NS instance'''
+ ns_instance = ctx.obj.ns.get(ns)
alarm = {}
alarm['alarm_name'] = name
- alarm['ns_name'] = ns
+ alarm['ns_id'] = ns_instance['_id']
+ alarm['correlation_id'] = ns_instance['_id']
alarm['vnf_member_index'] = vnf
alarm['vdu_name'] = vdu
alarm['metric_name'] = metric
exit(1)
-@cli.command(name='ns-alarm-delete')
-@click.argument('name')
-@click.pass_context
-def ns_alarm_delete(ctx, name):
- '''deletes an alarm
-
- NAME: name of the alarm to be deleted
- '''
- try:
- check_client_version(ctx.obj, ctx.command.name)
- ctx.obj.ns.delete_alarm(name)
- except ClientException as inst:
- print(inst.message)
- exit(1)
+#@cli.command(name='ns-alarm-delete')
+#@click.argument('name')
+#@click.pass_context
+#def ns_alarm_delete(ctx, name):
+# '''deletes an alarm
+#
+# NAME: name of the alarm to be deleted
+# '''
+# try:
+# check_client_version(ctx.obj, ctx.command.name)
+# ctx.obj.ns.delete_alarm(name)
+# except ClientException as inst:
+# print(inst.message)
+# exit(1)
####################
def ns_metric_export(ctx, ns, vnf, vdu, metric, interval):
'''exports a metric to the internal OSM bus, which can be read by other apps
'''
+ ns_instance = ctx.obj.ns.get(ns)
metric_data = {}
- metric_data['ns_name'] = ns
+ metric_data['ns_id'] = ns_instance['_id']
+ metric_data['correlation_id'] = ns_instance['_id']
metric_data['vnf_member_index'] = vnf
metric_data['vdu_name'] = vdu
metric_data['metric_name'] = metric
try:
check_client_version(ctx.obj, ctx.command.name)
if not interval:
- ctx.obj.ns.export_metric(metric_data)
+ print '{}'.format(ctx.obj.ns.export_metric(metric_data))
else:
i = 1
while True:
- ctx.obj.ns.export_metric(metric_data)
+ print '{} {}'.format(ctx.obj.ns.export_metric(metric_data),i)
time.sleep(int(interval))
i+=1
except ClientException as inst:
raise ClientException(message)
def create_alarm(self, alarm):
- ns = self.get(alarm['ns_name'])
- alarm['ns_id'] = ns['_id']
- alarm.pop('ns_name')
data = {}
data["create_alarm_request"] = {}
data["create_alarm_request"]["alarm_create_request"] = alarm
try:
http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
postfields_dict=data)
- if resp:
- resp = json.loads(resp)
- #print 'RESP: {}'.format(resp)
- if not resp:
- raise ClientException('unexpected response from server: '.format(
- resp))
- print 'Alarm created'
+ if http_code in (200, 201, 202, 204):
+ #resp = json.loads(resp)
+ #print 'RESP: {}'.format(resp)
+ print 'Alarm created'
+ else:
+ raise ClientException('unexpected response from server: code: {}, resp: {}'.format(
+ http_code, resp))
except ClientException as exc:
message="failed to create alarm: alarm {}\nerror:\n{}".format(
alarm,
try:
http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
postfields_dict=data)
- if resp:
- resp = json.loads(resp)
- #print 'RESP: {}'.format(resp)
- if not resp:
- raise ClientException('unexpected response from server: '.format(
- resp))
- print 'Alarm deleted'
+ if http_code in (200, 201, 202, 204):
+ #resp = json.loads(resp)
+ #print 'RESP: {}'.format(resp)
+ print 'Alarm deleted'
+ else:
+ raise ClientException('unexpected response from server: code: {}, resp: {}'.format(
+ http_code, resp))
except ClientException as exc:
message="failed to delete alarm: alarm {}\nerror:\n{}".format(
alarm,
raise ClientException(message)
def export_metric(self, metric):
- ns = self.get(metric['ns_name'])
- metric['ns_id'] = ns['_id']
- metric.pop('ns_name')
data = {}
data["read_metric_data_request"] = metric
try:
http_code, resp = self._http.post_cmd(endpoint='/test/message/metric_request',
postfields_dict=data)
- if resp:
- resp = json.loads(resp)
- #print 'RESP: {}'.format(resp)
- if not resp:
- raise ClientException('unexpected response from server: '.format(
- resp))
- print 'Metric exported'
+ if http_code in (200, 201, 202, 204):
+ #resp = json.loads(resp)
+ #print 'RESP: {}'.format(resp)
+ return 'Metric exported'
+ else:
+ raise ClientException('unexpected response from server: code: {}, resp: {}'.format(
+ http_code, resp))
except ClientException as exc:
message="failed to export metric: metric {}\nerror:\n{}".format(
metric,