Browse Source

Add reportbot announcement method

master
Chris Smith 6 years ago
parent
commit
7c11da7def
1 changed files with 14 additions and 0 deletions
  1. 14
    0
      main.py

+ 14
- 0
main.py View File

@@ -1,4 +1,5 @@
1 1
 import hashlib
2
+import socket
2 3
 
3 4
 import jenkins
4 5
 import requests
@@ -76,6 +77,19 @@ def get_gitea_repos():
76 77
         yield repo["full_name"], repo["ssh_url"], repo["clone_url"]
77 78
 
78 79
 
80
+def reportbot_announce(message):
81
+    try:
82
+        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
83
+            host = os.environ["LAS_REPORTBOT_ADDRESS"].split(":")
84
+            sock.connect((host[0], int(host[1])))
85
+            sock.sendall(
86
+                f"{os.environ['LAS_REPORTBOT_PREFIX']} {message}\n".encode("utf-8")
87
+            )
88
+            app.logger.info(f"Report bot response: {sock.recv(512)}")
89
+    except Exception:
90
+        app.logger.exception("Unable to send report bot message")
91
+
92
+
79 93
 repos = dict((name, [ssh, clone]) for name, ssh, clone in get_gitea_repos())
80 94
 jobs = list(get_jenkins_jobs())
81 95
 app = Flask(__name__)

Loading…
Cancel
Save