Compare commits
No commits in common. "ab5c6e771287cfbeeabc41be0b81e096f999eb45" and "cb914671d234046c28dec3bddc98863cae7cb54c" have entirely different histories.
ab5c6e7712
...
cb914671d2
2 changed files with 4 additions and 50 deletions
|
@ -4,7 +4,6 @@ import logging
|
||||||
import signal
|
import signal
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from requests.exceptions import ConnectionError
|
|
||||||
from multiprocessing import Process, Event, Queue
|
from multiprocessing import Process, Event, Queue
|
||||||
from logging.handlers import QueueHandler
|
from logging.handlers import QueueHandler
|
||||||
from imapclient import IMAPClient, exceptions
|
from imapclient import IMAPClient, exceptions
|
||||||
|
@ -36,8 +35,7 @@ class MailboxNotifier(object):
|
||||||
with IMAPClient(self.mailbox.imap_host) as self.imap:
|
with IMAPClient(self.mailbox.imap_host) as self.imap:
|
||||||
self.imap.login(self.mailbox.imap_user,
|
self.imap.login(self.mailbox.imap_user,
|
||||||
self.mailbox.imap_pass)
|
self.mailbox.imap_pass)
|
||||||
self.imap.select_folder("INBOX",
|
self.imap.select_folder("INBOX", readonly=True)
|
||||||
readonly=self.mailbox.read_only)
|
|
||||||
self.log.info("Connected to INBOX")
|
self.log.info("Connected to INBOX")
|
||||||
messages = self.imap.search("UNSEEN")
|
messages = self.imap.search("UNSEEN")
|
||||||
if len(messages) > 0:
|
if len(messages) > 0:
|
||||||
|
@ -115,9 +113,6 @@ class MailboxNotifier(object):
|
||||||
if target.service == "mattermost" and target.enabled:
|
if target.service == "mattermost" and target.enabled:
|
||||||
self.send_mattermost(target.target, text)
|
self.send_mattermost(target.target, text)
|
||||||
|
|
||||||
if target.service == "http_get" and target.enabled:
|
|
||||||
self.send_http_get(target.target)
|
|
||||||
|
|
||||||
def send_pushover(self, po_user, text):
|
def send_pushover(self, po_user, text):
|
||||||
notifier = Notifier.get(Notifier.service == "pushover")
|
notifier = Notifier.get(Notifier.service == "pushover")
|
||||||
url = "https://api.pushover.net/1/messages.json"
|
url = "https://api.pushover.net/1/messages.json"
|
||||||
|
@ -138,15 +133,11 @@ class MailboxNotifier(object):
|
||||||
self.log.debug(response.status_code)
|
self.log.debug(response.status_code)
|
||||||
self.log.debug(response.text)
|
self.log.debug(response.text)
|
||||||
|
|
||||||
def send_http_get(self, url):
|
|
||||||
response = requests.get(url)
|
|
||||||
self.log.debug(response.status_code)
|
|
||||||
self.log.debug(response.text)
|
|
||||||
|
|
||||||
def shutdown_handler(signal, frame):
|
def shutdown_handler(signal, frame):
|
||||||
_shtudown.set()
|
_shtudown.set()
|
||||||
|
|
||||||
def logger_thread(log_queue, url):
|
def logger_thread(log_queue):
|
||||||
logging.debug("starting logger thread")
|
logging.debug("starting logger thread")
|
||||||
while True:
|
while True:
|
||||||
entry = log_queue.get()
|
entry = log_queue.get()
|
||||||
|
@ -155,12 +146,6 @@ def logger_thread(log_queue, url):
|
||||||
break
|
break
|
||||||
logger = logging.getLogger(entry.name)
|
logger = logging.getLogger(entry.name)
|
||||||
logger.handle(entry)
|
logger.handle(entry)
|
||||||
if url is not None:
|
|
||||||
try:
|
|
||||||
r = requests.get(url)
|
|
||||||
|
|
||||||
except ConnectionError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def event_thread(event_queue):
|
def event_thread(event_queue):
|
||||||
logging.debug("starting event thread")
|
logging.debug("starting event thread")
|
||||||
|
@ -192,8 +177,6 @@ def main():
|
||||||
db.init(args.store, pragmas={'journal_mode': 'wal'})
|
db.init(args.store, pragmas={'journal_mode': 'wal'})
|
||||||
create_tables()
|
create_tables()
|
||||||
|
|
||||||
monitor_url = System.get_or_none(System.key == "monitor_url")
|
|
||||||
|
|
||||||
log_queue = Queue()
|
log_queue = Queue()
|
||||||
event_queue = Queue()
|
event_queue = Queue()
|
||||||
processes = []
|
processes = []
|
||||||
|
@ -208,8 +191,7 @@ def main():
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logging.debug("starting up main")
|
logging.debug("starting up main")
|
||||||
log_thread = threading.Thread(target=logger_thread,
|
log_thread = threading.Thread(target=logger_thread, args=(log_queue,))
|
||||||
args=(log_queue,monitor_url.value,))
|
|
||||||
log_thread.start()
|
log_thread.start()
|
||||||
e_thread = threading.Thread(target=event_thread, args=(event_queue,))
|
e_thread = threading.Thread(target=event_thread, args=(event_queue,))
|
||||||
e_thread.start()
|
e_thread.start()
|
||||||
|
|
|
@ -5,7 +5,7 @@ from playhouse.sqlite_ext import SqliteExtDatabase
|
||||||
db = SqliteExtDatabase(None)
|
db = SqliteExtDatabase(None)
|
||||||
migrator = SqliteMigrator(db)
|
migrator = SqliteMigrator(db)
|
||||||
|
|
||||||
db_schema = "2"
|
db_schema = "1"
|
||||||
|
|
||||||
class BaseModel(Model):
|
class BaseModel(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -21,7 +21,6 @@ class Mailbox(BaseModel):
|
||||||
imap_user = CharField()
|
imap_user = CharField()
|
||||||
imap_pass = CharField()
|
imap_pass = CharField()
|
||||||
last_check = DateTimeField(null=True)
|
last_check = DateTimeField(null=True)
|
||||||
read_only = BooleanField(default=True)
|
|
||||||
|
|
||||||
class Events(BaseModel):
|
class Events(BaseModel):
|
||||||
user = CharField()
|
user = CharField()
|
||||||
|
@ -45,30 +44,3 @@ def create_tables():
|
||||||
with db:
|
with db:
|
||||||
if not db.table_exists(System._meta.table_name):
|
if not db.table_exists(System._meta.table_name):
|
||||||
db.create_tables(tables)
|
db.create_tables(tables)
|
||||||
System.replace(key="schema", value=db_schema).execute()
|
|
||||||
|
|
||||||
else:
|
|
||||||
schema_ver = System.get_or_none(key="schema")
|
|
||||||
migrate_tables(schema_ver)
|
|
||||||
|
|
||||||
def migrate_tables(schema_ver):
|
|
||||||
if schema_ver is None or schema_ver.value == "1":
|
|
||||||
schema_ver = migrate_v2()
|
|
||||||
|
|
||||||
# if schema_ver == "2":
|
|
||||||
# schema_ver = migrate_v3()
|
|
||||||
|
|
||||||
System.replace(key="schema", value=db_schema).execute()
|
|
||||||
|
|
||||||
def migrate_v2():
|
|
||||||
# migration to schema version 2
|
|
||||||
read_only = BooleanField(default=True)
|
|
||||||
migrate(
|
|
||||||
migrator.add_column(
|
|
||||||
Mailbox._meta.table_name, 'read_only', read_only),
|
|
||||||
)
|
|
||||||
return "2"
|
|
||||||
|
|
||||||
# def migrate_v3():
|
|
||||||
# # migration to schema version 3
|
|
||||||
# return "3"
|
|
||||||
|
|
Loading…
Reference in a new issue