Monit and KDE Desktop notifications

I’m running a Monit based monitoring solution, but I do not have an email server (that I can use), so that when Monit Alerts happen, I receive a notification that something is wrong.

So I built a quick notification system, based in Python, that when a Monit detects an error, it notifies me by activating a Kde Notification on my desktop…

The solution that I use is quite simple and quick (Warning it’s an hack…):

My solution uses a python based network server running on my desktop listening for messages, and a python client deployed on the Monit server that sends messages, when called.

In short, the running server on my KDE desktop waits for a connection on a specific port, and when one connection is established it reads any text that comes on the connection payload and displays it using the KDE notification system:

MonitServer.py

## Monit Desktop Notification Network server
import socket
import sys
import knotify
import dbus

## Constants definition
HOST = ''    # Host IP Address. Empty means that we are the host
PORT = 29876    # Listening port. Choose any above 1024. The client must use the same port...
ADDR = (HOST,PORT)
BUFSIZE = 4096

## Send notification for the KDE notification system
def notify(title, text):
   knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify")
   knotify.event("warning", "kde", [], title, text, [], [], 0, 0,
   dbus_interface="org.kde.KNotify")

print 'Server Started'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
# Bind socket to local host and port
try:
  s.bind((HOST, PORT))
except socket.error as msg:
    print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
    sys.exit()
print 'Socket bind complete'

#Start listening on socket
s.listen(10)
print 'Socket now listening'

#now keep talking with the client
while 1:
  #wait to accept a connection - blocking call
  conn, addr = s.accept()
  print 'Connected with ' + addr[0] + ':' + str(addr[1])
  # Read the message that comes from the monit server.
  data = conn.recv(1024)
  # Send the message to the KDE notification system
  notify("Monit Alarm!", data)

s.close()

At the Monit server, I placed the following files at the Monit bin directory: notify.py and notify.sh:

notify.py

from socket import *
import sys
from datetime import datetime

HOST = '192.168.1.200'       # My machine IP. Change to the IP where the NotifyServe.py is running
PORT = 29876       
ADDR = (HOST,PORT)

cli = socket( AF_INET,SOCK_STREAM)
cli.connect((ADDR))
print len(sys.argv)
if ( len(sys.argv) > 1 ):
  message = str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + ": " + sys.argv[1]
  cli.send( message )
else:
  cli.send("Undefined Alert!")
cli.close()

Notify.py receives a message passed as a command line parameter and sends it to the NotifyServer running on the desktop machine.

The notify.sh shell script is a wrapper for the Monit server to call the monit.py script. Keep in mind that you must use absolute paths in every single file, otherwise it won’t work.

#!/bin/bash
/usr/bin/python2      /home/monitor/monit/bin/notify.py   $1

Now on the monitrc file we can change the alert lines from (for example):

check program System_status with path "/home/monitor/ShMonitor/SystemStatus.sh"
  if status !=0 then alert

to

check program System_status with path "/home/monitor/ShMonitor/SystemStatus.sh"
  if status !=0 for 15 cycles then exec "/home/monitor/monit/bin/notify.sh SystemStatus_Problem"

I added the for 15 cycles to avoid being flooded with notifications while I solve the issue… But it really depends of the monitoring pooling cycle. Adjust as required.

So, there it is, some code snippets gather across the web, allows me to have Monit notifications right at my desktop :)

 

 

 

Synology Cloudstation on Kubuntu/KDE Desktop

One of the softwares available for the Synology is Cloudstation that mimics Dropbox functionality but with your own server (in this case your Synology device). For the Cloustation server there are several clients available, and one of them is CloudStation for Linux.

But I run Kubuntu version of Ubuntu with the KDE desktop, and during installation of the CloudStation for Linux/Ubuntu, one of the installation steps by the Cloudstation install program  is to run apt-get where Nautilus, Brasero and a lot of other supporting libraries are required to be installed.

But, as I’ve found out, those packages are only needed for file manager integration, not for the functionality of the CloudStation software.

So just answer NO to the request of packages (you may want to keep a copy of the package list for future installation), and let CloudStation install.

On my KDE 4.11.3 it CloudStation works fine, and it has the Status icon on the Systray, without the required Nautilus libraries. Of course there is no Dolphin integration.

KDE device notifier and Konqueror/Dolphin file manager

This may seem a simple issue, but it took me a while to find why “Open with File Manager” on the device manager opened up the Konqueror file manager instead of Dolphin…

To change it’s easy. Just go to System Settings and Default Aplications. Choose File Manager, and there choose your File Manager of preference.

That’s it.

Kubuntu upgrade from 12.04 to 13.04

Despite Kubuntu 12.04 being a LTS release, and after some weeks upgrading to 13.04 on my personal desktop computer, I decided to do the same on my Work Laptop.

Things didn’t ran as expected…

First the upgrade from 12.04 to 12.10 deleted a bunch of packages, by my command :( and I ended up with no graphical display… A quick look at Xorg.0.log file showed me that my Xorger’s driver for my Intel graphic card was gone.

Anyway, I’ve installed the xservers-xorg-video-intel package and proceeded to upgrade to 13.04.

At the end despite having a graphical desktop, after login on KDE, a qdbus error appeared… qdbus package was missing… (apt-get install qdbus).

Also on 12.04 the transition from the login greeter to the desktop is silky smooth (it is on my desktop), on my laptop it blanks showing a black screen with a mouse cursor, but the desktop shows up abruptly. I don’t have now the KDE logon progress icons…

And finally, DNS settings from my DHCP servers didn’t worked, I had to manually add the dns servers IP to resolv.conf…  This issue was also a missing package, namely dnsmaq. After adding up the nameserver 127.0.0.1 to my /etc/resolv.conf file, everything is up….

Let’s see what is waiting again in the dark…

Firefox Open Download Directory Action on KDE/KUbuntu

I had a bit of a strange issue with FireFox and Kde 4.7 on Kubuntu 11.X.

After downloading a file with Firefox, on the Dowloads Firefox windows, right clicking the downloaded file for the Open Download Directory action, instead of opening the Dolphin File Manager, it opened the KdeSVN application… Very, very annoying.

To solve this you need to reconfigure KDE, probably due to the fact that KDESvn was installed:

1) Goto System Settings
2) Select Default Applications
3) Select FileManagers
4) Deselect and select Dolphin
5) Apply
6) Restart Firefox

It should work now.

[K]Ubuntu on Asus N73SV

So my employer replaced my old work laptop HP nx9420 by a new ASUS N73SV, more precisely N73SV-V1G-TZ393V, which by the way is  a great name (not…). The Asus N73 is the bigger screen brother of the Asus N53.

My old HP was able to do any work I could ask for, but it’s limitations on handling virtual machines where showing up, delaying work significantly. This Asus is a completly different beast. It’s fast, and has 3 SODIMM slots, so right now I have it with 12GB of RAM (8GB are two 4GB of Kingston memory plus the original 4GB of RAM). To open up it, you must remove the keyboard (small tabs near the ESC key, F5, F9, PRTSC and End at the top)  and one SODIMM slot is available right away (on th Q2630 CPU’s). Then after removing some screws (check the manual), the disk bay and remaining memory slot is also available at the bottom by removing the bottom cover.

The first thing to do with it was of course to nuke Windows 7, and after much indecision between KUbuntu and Arch, I installed Kubuntu 11.04 64 bit edition. After some fiddling with partitioning (I just left the original recovery partition), everything installed smoothly. Going to KUbuntu was more for getting a full working computer as fast as I can, without too much fiddling, but I left a partition to try out Arch on my spare time.

So what works out of the box? Well almost everything. Let’s talk about what doesn’t work.

First I’ve followed these instructions on the Ubuntu Help Pages for the N53SV and installed the acpi4asus_dkms, blueetooth driver and Bumblebee for the dual card support.

Still USB3 with USB2 devices doesn’t work, and hibernation/suspension doesn’t work. Regarding USB3 it’s a confirmed bug, so in the near future a solution will be available. Regarding hibernation/suspension I think it’s related to the NVidia card driver, but not sure because the computer does shutdown, but comes up to a black screen.

Also this specific version of the N73SV ha a DVB-T card with the Philips chipset SAA7231. It doesn’t work and there is no driver available because the manufacturer doesn’t won’t to support Linux. There is a two year old drive, but I think I doesn’t work with the recent kernels.

At the end I have a full accelerated desktop, dual monitor support, Wifi, bluetooth, networking, webcam, USB2, TurboBoost and the left media keys working fine.

Moving from the old computer, was just a matter of copying my home directory and following these instructions to re-install all software.

The good:

  • Screen size and quality: Superb
  • Fast, fast, fast
  • Big Hard disk (640GB). Available slot for a second hardisk/SSD
  • Allows a lot of memory: 12GB
  • ExpressGate

The bad:

  • Fiddly keyboard, getting time to get used to.
  • Keyboard sunken a bit when pressing keys.
  • No ExpressCard Slot
  • No eSata port
  • Location of some USB ports at the back is not very practical.

Firefox opens PDF’s files with GIMP

One annoying issue that I had for some time, was that after downloading a PDF file, double clicking on the filename in the FireFox Downloads window, open up GIMP, instead of Acrobat or Okular…

To solve the issue:

1) Get root: sudo -s
2) Goto /usr/share/applications
3) Edit the mimeinfo.cache file
4) Search for pdf
5) You find a line named something like: application/pdf
6) Remove the gimp.desktop from the line, keeping the other applications, or not
7) Save
8) Restart firefox
10) Problem solved