Monitor Mojo outages with Python and Skype

It is a script that Python monitors the stop of the 3D printer Mojo and notifies you via Skype.

Monitor Mojo's logs and send all logs via Skype chat for the time being. I will make a phone call when it stops.

Since Mojo stops frequently in a restartable state, I will notify you when it stops. It does not restart automatically because it is necessary to visually check for print abnormalities.

Library used

How to use

Just set the path to the Mojo log and your Skype contacts If you execute it, monitoring will start

reference

script

python


# -*- coding: utf-8 -*-

import time
import os
import re
import numpy as np
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
import Skype4Py

#Path to Mojo's log
BASEDIR = "C:/ProgramData/Mojo/Mojo 3D Printer Software/Log/"
log_filename = "SystemLog.log"

#contact information
user_name = 'Frend name'

#-------Skype4Py examples->callfriend.Copy from py(For call)--------->
# This variable will get its actual value in OnCall handler
CallStatus = 0

# Here we define a set of call statuses that indicate a call
# has been either aborted or finished
CallIsFinished = set([Skype4Py.clsFailed, Skype4Py.clsFinished,
                       Skype4Py.clsMissed, Skype4Py.clsRefused,
                       Skype4Py.clsBusy, Skype4Py.clsCancelled]);

def AttachmentStatusText(status):
   return skype.Convert.AttachmentStatusToText(status)

def CallStatusText(status):
    return skype.Convert.CallStatusToText(status)

# This handler is fired when status of Call object has changed
def OnCall(call, status):
    global CallStatus
    CallStatus = status
    print 'Call status: ' + CallStatusText(status)

# This handler is fired when Skype attatchment status changes
def OnAttach(status):
    print 'API attachment status: ' + AttachmentStatusText(status)
    if status == Skype4Py.apiAttachAvailable:
        skype.Attach()
#<--Copy and paste so far----------------------------------------------------

#Attach chat settings to Skype
skype = Skype4Py.Skype()
if not skype.Client.IsRunning:
    print 'Starting Skype..'
    skype.Client.Start()
skype.Attach()
skype.OnAttachmentStatus = OnAttach
skype.OnCallStatus = OnCall
chat = skype.CreateChatWith(user_name)
chat.SendMessage('Mojo''s watchdog has been started!')

#Mojo log monitoring
class ChangeHandler(FileSystemEventHandler):

    def on_modified(self, event):
        if event.is_directory:
            return
        else:
            time.sleep(5)
            data = np.loadtxt(
               os.path.join(BASEDIR, log_filename),
               delimiter="\n", dtype=str)
            #-Last line at 1(Latest log information)Only output
            print(data[-1])
            chat.SendMessage(data[-1])
            #Make a call when Pause is included
            n = len(re.findall('pause', data[-1])) + \
                len(re.findall('Paused', data[-1]))
            if n > 0:
			     skype.PlaceCall(user_name)
                while not CallStatus in CallIsFinished:
                    pass

#"Watchdog is quite useful for file monitoring"Copy the code of
if __name__ in '__main__':
    while 1:
        event_handler = ChangeHandler()
        observer = Observer()
        observer.schedule(event_handler, BASEDIR, recursive=True)
        observer.start()
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()

Recommended Posts

Monitor Mojo outages with Python and Skype
Programming with Python and Tkinter
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
python with pyenv and venv
With skype, notify with skype from python!
Works with Python and R
Communicate with FX-5204PS with Python and PyUSB
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
Neural network with OpenCV 3 and Python 3
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
Scraping with Python, Selenium and Chromedriver
Scraping with Python and Beautiful Soup
Monitor Python web apps with Prometheus
Monitor Python application performance with Dynatrace ♪
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Reading and writing NetCDF with Python
I played with PyQt5 and Python3
Reading and writing CSV with Python
Multiple integrals with Python and Sympy
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Sugoroku game and addition game with python
FM modulation and demodulation with Python
Data pipeline construction with Python and Luigi
Calculate and display standard weight with python
FM modulation and demodulation with Python Part 3
[Automation] Manipulate mouse and keyboard with Python
Passwordless authentication with RDS and IAM (Python)
Python installation and package management with pip
Using Python and MeCab with Azure Databricks
POST variously with Python and receive with Flask
Capturing images with Pupil, python and OpenCV
Fractal to make and play with Python
A memo with Python2.7 and Python3 on CentOS
Use PIL and Pillow with Cygwin Python
Create and decrypt Caesar cipher with python
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Reading and writing JSON files with Python
Dealing with "years and months" in Python
I installed and used Numba with Python3.5
Tweet analysis with Python, Mecab and CaboCha
Linking python and JavaScript with jupyter notebook
Traffic monitoring with Kibana, ElasticSearch and Python
FM modulation and demodulation with Python Part 2
Encrypt with Ruby (Rails) and decrypt with Python
Easily download mp3 / mp4 with python and youtube-dl!
Operate home appliances with Python and IRKit
Clean python environment with pythonz and virtualenv
Practice web scraping with Python and Selenium
Easy web scraping with Python and Ruby
Importing and exporting GeoTiff images with Python
I'm using tox and Python 3.3 with Travis-CI
Happy GUI construction with electron and python
Use Python and MeCab with Azure Functions
Touch AWS with Serverless Framework and Python