enable ssl

This commit is contained in:
deflax 2024-02-07 15:38:49 +02:00 committed by GitHub
parent 709326ff21
commit 2de33ceeb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ z_user = 'USER'
z_pass = 'PASS'
server = 'irc.example.com'
port = 9020
channel = '#example'
nick = 'steinvord'
botnick = 'Steinvord'
@ -20,9 +21,9 @@ botuser = 'steinvord'
encoding = 'utf-8'
calibrate = 0
### begin
import sys, socket, time, re, datetime
import sys, time, re, datetime
import socket, ssl
from pyzabbix import ZabbixAPI
from difflib import Differ
@ -39,27 +40,33 @@ except Exception as e:
exit(3)
print("Connected to Zabbix API Version %s" % zapi.api_version())
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #defines the socket
irc_C = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #defines the socket
irc = ssl.wrap_socket(irc_C)
print("Establishing connection to [%s]" % (server))
irc.connect((server, 6667)) #connects to the server
irc.connect((server, port)) #connects to the server
irc.setblocking(False)
sock_auth = "USER "+ botuser +" "+ botuser +" "+ botuser +" :This is the Steinvord bot!\n"
sock_nick = "NICK "+ botnick +"\n"
sock_nicksrv = "PRIVMSG nickserv :iNOOPE\r\n"
sock_join = "JOIN "+ channel +"\n"
irc.send(sock_auth.encode(encoding))
irc.send(sock_nick.encode(encoding))
irc.send(sock_nicksrv.encode(encoding))
time.sleep(10)
irc.send(sock_join.encode(encoding))
def environment():
currtemp = float(zapi.item.get(filter={'hostid': '10125', 'itemid': '26379'})[0]['lastvalue'])
currhumid = calibrate + float(zapi.item.get(filter={'hostid': '10125', 'itemid': '26618'})[0]['lastvalue'])
currtemp = float(zapi.item.get(filter={'hostid': '10137', 'itemid': '28145'})[0]['lastvalue'])
currhumid = calibrate + float(zapi.item.get(filter={'hostid': '10137', 'itemid': '28144'})[0]['lastvalue'])
t_result = 't=' + str(currtemp) + '°C'
if currtemp > 24:
if currtemp > 27:
t_result += ' !! WARNING !!'
elif currtemp > 32:
t_result += ' !! CRITICAL !!'
t_result += ' h=' + str(currhumid) + '%'
t_sock_result = 'PRIVMSG ' + channel + ' :' + t_result + '\n'
irc.send(t_sock_result.encode(encoding))
@ -72,8 +79,8 @@ while True:
if counter == 60:
counter = 0
ctime = datetime.datetime.now()
if int(ctime.minute) == 20:
environment() # print env data every 20 minutes
#if int(ctime.minute) == 20:
# environment() # print env data every 20 minutes
triggers = zapi.trigger.get(only_true=1,
skipDependent=1,
@ -129,8 +136,8 @@ while True:
sock_result = 'PRIVMSG ' + channel + " :" + result + '\n'
irc.send(sock_result.encode(encoding))
time.sleep(1)
if decoded_text.find('!env') != -1:
environment()
#if decoded_text.find('!env') != -1:
# environment()
# Prevent Timeout
if decoded_text.find('PING') != -1:
@ -140,4 +147,3 @@ while True:
continue
exit(0)