2 # -*- coding: utf-8 -*-
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 __author__
= "Alfonso Tierno, alfonso.tiernosepulveda@telefonica.com"
23 __date__
= "$2019-05-31$"
25 version_date
= "May 2019"
29 print("Usage: ", sys
.argv
[0], "topic key message")
30 print(" Sends a kafka message using URL test of NBI")
31 print(" host is defined by env OSMNBI_HOST (localhost by default)")
32 print(" port is defined by env OSMNBI_PORT (9999 by default)")
36 if __name__
== "__main__":
38 if "--help" in sys
.argv
:
42 if len(sys
.argv
) != 4:
44 "missing parameters. Type --help for more information", file=sys
.stderr
48 topic
, key
, message
= sys
.argv
[1:]
49 host
= getenv("OSMNBI_HOST", "localhost")
50 port
= getenv("OSMNBI_PORT", "9999")
51 url
= "https://{host}:{port}/osm/test/message/{topic}".format(
52 host
=host
, port
=port
, topic
=topic
57 r
= requests
.post(url
, data
=yaml
.safe_dump(data
), verify
=False)
58 if r
.status_code
not in (200, 201, 202, 204):
59 print("Received code={}, content='{}'".format(r
.status_code
, r
.text
))
61 print("{} -> {}: {}".format(topic
, key
, message
))