Commits

catapela committed d264160

0.1.3
canges in readme, kernel, init

  • Participants
  • Parent commits cb7b98a

Comments (0)

Files changed (17)

+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>raid-guard</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.python.pydev.pythonNature</nature>
+	</natures>
+</projectDescription>

File .pydevproject

+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?>
+
+<pydev_project>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python2.7</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
+</pydev_project>

File .settings/org.eclipse.core.resources.prefs

+eclipse.preferences.version=1
+encoding/setup.py=utf-8
+The MIT License (MIT)
+
+Copyright (c) 2013 Andreas Fritz
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+include LICENSE README.rst raid_guard.ini
+===========
+Description
+===========
+
+Monitoring hard discs in a raid system on linux servers. Raid Guard runs as a 
+daemon and will send mails on specific events.
+
+**License**
+
+    MIT License
+
+**Notes**
+
+    * Only tested on a linux server
+
+========
+Features
+========
+
+    * runs as a daemon.
+    * send a mail if a hard drive loss.
+    * setup via configuration file.
+
+============
+Installation
+============
+
+**Dependences**
+
+    * deiman (https://pypi.python.org/pypi/deiman/)
+    * iniparse (https://pypi.python.org/pypi/iniparse/)
+
+**Installation / Deinstallation**
+
+    *with pip*
+        
+        ::
+        
+            pip install raid-guard
+    
+            pip uninstall raid-guard
+
+
+    *or setup.py*
+
+        1. Unpack your package.
+        2. Open a terminal and change to the folder which contains the setup.py and type
+
+        ::
+
+            python setup.py install
+   
+=====
+Setup
+=====
+    
+    * edit the /usr/share/raid_guard/raid_guard.ini an copy it to /root/.raid_guard.ini
+      or start the prog the first time and the ini file will copied automaticly to root.
+    * Add an entry into the /etc/rc.local file: /usr/local/bin/raid_guard start
+
+=====
+Usage
+=====
+
+    *raid_guard [options]*
+    
+        options are: start, stop, status, help, test, logfile
+    
+=====
+Hints
+=====
+
+    * The logfile is stored at /var/log/raid_guard.log

File raid_guard.egg-info/PKG-INFO

+Metadata-Version: 1.1
+Name: raid-guard
+Version: 0.1.3
+Summary: raid hard disc monitoring daemon for linux servers
+Home-page: http://www.sources.e-blue.eu/
+Author: Andreas Fritz
+Author-email: raid_guard@bitzeit.eu
+License: UNKNOWN
+Download-URL: https://pypi.python.org/pypi
+Description: ===========
+        Description
+        ===========
+        
+        Monitoring hard discs in a raid system on linux servers. Raid Guard runs as a 
+        daemon and will send mails on specific events.
+        
+        **License**
+        
+            MIT License
+        
+        **Notes**
+        
+            * Only tested on a linux server
+        
+        ========
+        Features
+        ========
+        
+            * runs as a daemon.
+            * send a mail if a hard drive loss.
+            * setup via configuration file.
+        
+        ============
+        Installation
+        ============
+        
+        **Dependences**
+        
+            * deiman (https://pypi.python.org/pypi/deiman/)
+            * iniparse (https://pypi.python.org/pypi/iniparse/)
+        
+        **Installation / Deinstallation**
+        
+            *with pip*
+                
+                ::
+                
+                    pip install raid-guard
+            
+                    pip uninstall raid-guard
+        
+        
+            *or setup.py*
+        
+                1. Unpack your package.
+                2. Open a terminal and change to the folder which contains the setup.py and type
+        
+                ::
+        
+                    python setup.py install
+           
+        =====
+        Setup
+        =====
+            
+            * edit the /usr/share/raid_guard/raid_guard.ini an copy it to /root/.raid_guard.ini
+              or start the prog the first time and the ini file will copied automaticly to root.
+            * Add an entry into the /etc/rc.local file: /usr/local/bin/raid_guard start
+        
+        =====
+        Usage
+        =====
+        
+            *raid_guard [options]*
+            
+                options are: start, stop, status, help, test, logfile
+            
+        =====
+        Hints
+        =====
+        
+            * The logfile is stored at /var/log/raid_guard.log
+Keywords: raid hard-disk server monitoring daemon
+Platform: UNKNOWN
+Classifier: Development Status :: 3 - Alpha
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: Unix
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Environment :: Console
+Classifier: Natural Language :: English
+Classifier: Intended Audience :: System Administrators
+Classifier: Topic :: System :: Networking :: Monitoring
+Classifier: Topic :: System :: Networking :: Monitoring :: Hardware Watchdog
+Classifier: Topic :: System :: Systems Administration

File raid_guard.egg-info/SOURCES.txt

+LICENSE
+MANIFEST.in
+README.rst
+raid_guard.ini
+setup.py
+raid_guard/__init__.py
+raid_guard/kernel.py
+raid_guard/kernel.pyc
+raid_guard.egg-info/PKG-INFO
+raid_guard.egg-info/SOURCES.txt
+raid_guard.egg-info/dependency_links.txt
+raid_guard.egg-info/entry_points.txt
+raid_guard.egg-info/requires.txt
+raid_guard.egg-info/top_level.txt

File raid_guard.egg-info/dependency_links.txt

+

File raid_guard.egg-info/entry_points.txt

+[console_scripts]
+raid_guard = raid_guard:main
+

File raid_guard.egg-info/requires.txt

+deiman
+iniparse

File raid_guard.egg-info/top_level.txt

+raid_guard

File raid_guard.ini

+[mail]
+host_smtp = smtp.yourdomain.net
+host_username = your@username.eu
+host_password = yourpassword
+
+# you can leave this or use (better) a known one.
+mail_from = raidguard@server.eu
+
+# one or more recipients (comma seperated)
+mail_to = to@mydomain.eu
+
+
+[daemon]
+# interval in seconds
+check_interval = 36000
+
+# Alert conditions
+alert_raidstatus_ok = NO
+alert_raidstatus_malfunction = YES
+alert_raidstatus_unsure = YES

File raid_guard/__init__.py

+import sys
+import kernel
+import os
+from deiman.deiman import Deiman
+
+
+def main():
+    args = ('start', 'stop', 'status', 'logfile', 'test', 'help')
+    app_name = 'raid_guard'
+    d = Deiman("/tmp/%s.pid" % app_name)
+    if len(sys.argv) == 1 or sys.argv[1] not in args:
+        print("Usage: %s %s" % (app_name,list(args)))
+        sys.exit(2)
+    opt = sys.argv[1]
+    
+    if opt == 'start':
+        d.start()
+        print('Check status with: raid_guard status')
+        g = kernel.Guard()
+        g.start_daemon()
+        
+    elif opt== 'stop':
+        d.stop()
+        sys.exit(0)
+        
+    elif opt == 'status':
+        print('daemon status is:')
+        d.status()
+        print('')
+        print('For more information use: raid_guard logfile')
+        print('Get help with: raid_guard help')
+        sys.exit(0)
+        
+    elif opt == 'test':
+        kernel.run_test()
+        sys.exit()
+        
+    elif opt == 'help':
+        print(os.system('cat /usr/share/raid_guard/README.rst'))
+        sys.exit()
+        
+    elif opt == 'logfile':
+        if os.path.isfile('/var/log/raid_guard.log'):
+            print(os.system('cat /var/log/raid_guard.log'))
+        else:
+            print('Actual no log file.')
+        sys.exit()

File raid_guard/kernel.py

+#!/usr/bin/env python
+
+import os
+import smtplib
+from email.mime.text import MIMEText
+import sys
+import time
+from iniparse import INIConfig
+from string import lower
+import unittest
+import logging
+import shutil
+
+
+def init_logging(test=False):
+    # configure the logging module
+    if __name__ == '__main__':
+        # log path for development
+        logpath = '%s/raid_guard.log' % (os.environ['HOME'])
+        logging.basicConfig(filename=logpath,
+                            format='%(asctime)s %(message)s',
+                            filemode='w',
+                            level=logging.DEBUG
+                            )
+        logging.info('Log path for development: home/raid_guard.log')
+    elif test:
+        pass
+    else:
+        # log path for production
+        try:
+            logpath = '/var/log/raid_guard.log'
+            logging.basicConfig(filename=logpath,
+                                format='%(asctime)s %(message)s',
+                                level=logging.INFO
+                                )
+        except IOError as e:
+            raise IOError('%s. %s' % (e,'Run script as root!'))
+        
+
+def run_test():
+    suite1 = unittest.TestLoader().loadTestsFromTestCase(TestGuard)
+    suite2 = unittest.TestLoader().loadTestsFromTestCase(TestMail)
+    unittest.TextTestRunner(verbosity=2).run(suite1)
+    unittest.TextTestRunner(verbosity=2).run(suite2)
+    sys.exit()
+
+
+class Guard:
+    def __init__(self,mail_dict={},alerts=[2,3],ini_path=None,test=False):
+        """mail_dict must contain keywords: 
+        mail_dict={'value':'just a dict'}
+        and should:
+        mail_dict={
+        'mail_from':'mail@yourdomain.net',
+        'host_user':'your_mail_host_username',
+        'host_pass':'your_passw',
+        'host_smtp':'smtp.domain.net',
+        }
+        """
+        if test:
+            init_logging(test)
+        else:
+            init_logging()
+        
+        self.mail = mail_dict
+        self.allerts = alerts
+        self.initial_mail = False
+        self.sleep = 36000
+        
+        # if no mai dict in arguments than fetch ini file
+        if not mail_dict:
+            if not ini_path:
+                ini_file = '/root/.raid_guard.ini'
+                if not os.path.isfile(ini_file):
+                    shutil.copyfile('/usr/share/raid_guard/raid_guard.ini',ini_file)
+            else:
+                ini_file = ini_path
+            
+            logging.debug('there is no initial mail dict')
+            # read ini
+            if not os.path.isfile(ini_file):
+                m = '%s not found' % ini_file
+                logging.error(m)
+                raise IOError(m)
+            
+            # parser instance
+            parser = INIConfig(file(ini_file))
+            
+            # fetch values: value = parser['section']['key']
+            self.sleep = int(parser['daemon']['check_interval'])
+            
+            self.allerts = []
+            if lower(parser['daemon']['alert_raidstatus_ok']) == lower('YES'):
+                self.allerts.append(1)
+            if lower(parser['daemon']['alert_raidstatus_malfunction']) == lower('YES'):
+                self.allerts.append(2)
+            if lower(parser['daemon']['alert_raidstatus_unsure']) == lower('YES'):
+                self.allerts.append(3)
+            
+            self.mail['host_smtp'] = parser['mail']['host_smtp']
+            self.mail['host_user'] = parser['mail']['host_username']
+            self.mail['host_pass'] = parser['mail']['host_password']
+            self.mail['mail_from'] = parser['mail']['mail_from']
+            mailto = parser['mail']['mail_to']
+            mailto = mailto.strip(' ').replace(',','').replace('  ',' ').split()
+            self.mail['recipient_list'] = mailto
+            
+    def start_daemon(self, sleep=None):
+        logging.debug('daemon was started')
+        if not sleep:
+            sleep = self.sleep
+
+        # send status to admin
+        self.allert_admin(4)
+        
+        # this is the demon
+        while True:
+            self.check_raid()
+            time.sleep(sleep)
+    
+    def _get_status(self,inp):
+        """returns status as integer"""
+        st = str(inp)
+        st = st.replace('\n','').split(' ')
+        logging.debug('Status string to parse: %s' % st)
+        
+        if '[U_]' in st:
+            # raid is malfunction
+            logging.info('Raid status: Malfunction')
+            return 2
+        elif '[UU]' in st:
+            # raid is perfect
+            logging.info('Raid status: OK')
+            return 1
+        else:
+            # raid needs manual review
+            logging.info('Raid status: Unknown')
+            return 3
+        
+    def check_raid(self):
+        file = '/proc/mdstat'
+        o = open(file,'r')
+        data = o.read()
+        o.close()
+        status = self._get_status(data)
+        logging.debug('raid checked! Status: %s' % status)
+        if status in self.allerts:
+            self.allert_admin(status)
+        
+    def allert_admin(self,status):
+        subj='Raid Guard Disc Status'
+        
+        if status == 1:
+            text = 'Hard discs OK.'
+        elif status == 2:
+            text = 'Minimum one hard disc is defect! Check it with: "cat /proc/mdstat"'
+        elif status == 3:
+            text = "I'am unsure about your disks. Please check your raid and hard discs by your self."
+        elif status == 4:
+            text = 'Raid Guard demon is active now.'
+            subj = 'Raid Guard Status'
+        
+        m = Mail(self.mail)
+        m.create(subj=subj,message=text,recipients=self.mail['recipient_list'])
+        m.send()
+
+
+class Mail():
+    def __init__(self,data_dict):
+        """
+        data_dict={
+        'mail_from':'mail@yourdomain.net',
+        'host_user':'your_mail_host_username',
+        'host_pass':'your_passw',
+        'host_smtp':'smtp.domain.net',
+        }
+        """
+        self.data = data_dict
+        self.msg = None # for mime text instance
+        self.recipients = []
+        
+    def create(self,subj,message,recipients):
+        if not type(recipients) == list:
+            self.recipients = [recipients,]
+        else:
+            self.recipients = recipients
+        
+        self.msg = MIMEText(message.encode('utf-8'), 'plain', 'UTF-8')
+        self.msg['Subject'] = subj
+        self.msg['From'] = self.data['mail_from']
+        self.msg['To'] = ",".join(self.recipients)
+        self.msg['log_message'] = message
+
+    def send(self):
+        # Smtp login
+        try:
+            s = smtplib.SMTP(self.data['host_smtp'])
+            s.login(self.data['host_user'],self.data['host_pass'])
+            logging.debug('smtp login ok.')
+        except smtplib.socket.error as e:
+            m = '%s. %s' % (e, 'Check your raid_guard.ini. May your login data are wrong.')
+            logging.error(m)
+            raise smtplib.socket.error(m)
+        
+        # Sending the Mail
+        try:
+            # Send mail with the sender address of the mail form user.
+            s.sendmail(self.msg['From'], self.recipients, self.msg.as_string())
+            s.quit()
+            m = 'mail was send to %s with message: %s' % (self.recipients, self.msg['log_message'])
+            logging.info(m)
+            
+        except smtplib.SMTPSenderRefused as e:
+            # Ups that does not worked at all. Now we use 
+            # a different sender address.
+            # We try to send with our own host user email 
+            # address as sender address.
+            # We do it because mail host services often do not allow 
+            # send an email with an unknown mail address.
+            
+            # we can do it only if user name is an email address
+            if '@' in self.data['host_user']:
+                del self.msg['From']
+                self.msg['From'] = self.data['host_user'] # change the sender
+    
+                # and now sending the mail again
+                s.sendmail(self.msg['From'], self.recipients, self.msg.as_string())
+                s.quit()
+                
+                logging.warning("""
+                                Fall back: Alternate mail sending routine
+                                (changed your sender address) successful executed!
+                                probably your mail host don't allow to send an
+                                email with an unknown mail address
+                            """)
+                m = 'mail was send to %s with message: %s' % (self.recipients, self.msg['log_message'])
+                logging.info(m)
+            else:
+                t="""
+                    Probably your mail host don't allow to send an
+                    email with an unknown mail address
+                    """
+                m = '%s: %s' % (e, t)
+                logging.error(m)
+                raise smtplib.SMTPSenderRefused(m,'','')
+
+
+class TestMail(unittest.TestCase):
+    def setUp(self):
+        data_dict={
+            'mail_from':'m@yourd.eu',
+            'host_user':'your_mail_host_username',
+            'host_pass':'your_passw',
+            'host_smtp':'smtp.domain.net',
+            }
+        self.mail = Mail(data_dict)
+    
+    def test_mimetext_instance(self):
+        self.mail.create(subj='a subject',
+                         message=' a message',
+                         recipients= ['1@mm.eu', '2@mm.eu']
+                         )
+        self.assertEqual(self.mail.msg['Subject'], 'a subject')
+        self.assertEqual(self.mail.msg['From'], 'm@yourd.eu')
+        self.assertEqual(type(self.mail.msg['To']), type(''))
+        self.assertEqual(self.mail.msg['To'], '1@mm.eu,2@mm.eu')
+        
+    def test_send(self):
+        self.assertRaises(smtplib.SMTPAuthenticationError, self.mail.send)
+
+
+class TestGuard(unittest.TestCase):
+    def setUp(self):
+        d = {'value':'some dict'}
+        self.g = Guard(mail_dict=d,test=True)
+        self.pos = """2096064 blocks [2/2] [UU]
+        active raid1 sdb1[1] sda1[0]"""
+        self.neg = """active raid1 sda4[0] sdb4[1](F)
+        1822442815 blocks super 1.2 [2/1] [U_]"""
+        self.neg2 = """2096064 blocks [2/2] [UU]
+        active raid1 sdb1[1] sda1[0]
+        active raid1 sda4[0] sdb4[1](F)
+        1822442815 blocks super 1.2 [2/1] [U_]"""
+        self.non = """Personalities : 
+        unused devices: <none>"""
+        
+    def test_positive(self):
+        self.assertEqual(1, self.g._get_status(self.pos))
+        
+    def test_negative(self):
+        self.assertEqual(2, self.g._get_status(self.neg))
+        self.assertEqual(2, self.g._get_status(self.neg2))
+        
+    def test_non(self):
+        self.assertEqual(3, self.g._get_status(self.non))
+        
+
+if __name__ == '__main__':
+    ini_file = '%s/.raid_guard.ini' % os.environ['HOME']
+    g = Guard(ini_path=ini_file)
+    g.start_daemon()
+    
+    

File raid_gurad.py

-#!/usr/bin/env python
-
-import os
-import smtplib
-from email.mime.text import MIMEText
-import sys
-from deiman.deiman import Deiman
-import time
-from iniparse import INIConfig
-from string import lower
-import unittest
-import logging
-
-# configure the logging module
-try:
-    logpath = '/var/log/%s.log' % os.path.basename(__file__)
-    logging.basicConfig(filename=logpath,level=logging.INFO)
-except IOError:
-    logpath = '%s/%s.log' % (os.environ['HOME'],os.path.basename(__file__))
-    logging.basicConfig(filename=logpath,level=logging.INFO)
-
-def run_test():
-    suite1 = unittest.TestLoader().loadTestsFromTestCase(TestGuard)
-    suite2 = unittest.TestLoader().loadTestsFromTestCase(TestMail)
-    unittest.TextTestRunner(verbosity=2).run(suite1)
-    unittest.TextTestRunner(verbosity=2).run(suite2)
-    sys.exit()
-
-class Guard:
-    def __init__(self,mail_dict={},alerts=[2,3],ini_path=None):
-        """mail_dict must contain keywords: 
-        mail_dict={'value':'just a dict'}
-        """
-        if not ini_path:
-            ini_file = '/usr/share/raid_guard/raid_guard.ini'
-        else:
-            ini_file = ini_path
-        
-        self.mail = mail_dict
-        self.allerts = alerts
-        self.initial_mail = False
-        self.sleep = 36000
-        
-        # if no mai dict in arguments than fetch ini file
-        if not mail_dict:
-            # read ini
-            if not os.path.isfile(ini_file):
-                raise IOError('%s not found' % ini_file)
-            
-            # parser instance
-            parser = INIConfig(file(ini_file))
-            
-            # fetch values: value = parser['section']['key']
-            self.sleep = int(parser['daemon']['check_interval'])
-            
-            self.allerts = []
-            if lower(parser['daemon']['alert_raidstatus_ok']) == lower('YES'):
-                self.allerts.append(1)
-            if lower(parser['daemon']['alert_raidstatus_malfunction']) == lower('YES'):
-                self.allerts.append(2)
-            if lower(parser['daemon']['alert_raidstatus_unsure']) == lower('YES'):
-                self.allerts.append(3)
-            
-            self.mail['host_smtp'] = parser['mail']['host_smtp']
-            self.mail['host_user'] = parser['mail']['host_username']
-            self.mail['host_pass'] = parser['mail']['host_password']
-            self.mail['mail_from'] = parser['mail']['mail_from']
-            mailto = parser['mail']['mail_to']
-            mailto = mailto.strip(' ').replace(',','').replace('  ',' ').split()
-            self.mail['recipient_list'] = mailto
-            
-    def start_daemon(self, sleep=None):
-        if not sleep:
-            sleep = self.sleep
-
-        # send status to admin
-        self.allert_admin(4)
-        
-        # this is the demon
-        while True:
-            self.check_raid()
-            logging.info("""
-                        raid checked!
-                        """)
-            time.sleep(sleep)
-    
-    def _get_status(self,inp):
-        """returns status as integer"""
-        st = str(inp)
-        st = st.replace('\n','').split(' ')
-        if '[U_]' in st:
-            # raid is malfunction
-            return 2
-        elif '[UU]' in st:
-            # raid is perfect
-            return 1
-        else:
-            # raid needs manual review
-            return 3
-        
-    def check_raid(self):
-        mdstat = os.system('cat /proc/mdstat')
-        status = self._get_status(mdstat)
-        if status in self.allerts:
-            self.allert_admin(status)
-        
-    def allert_admin(self,status):
-        subj='Raid Guard Disc Status'
-        
-        if status == 1:
-            text = 'Hard discs OK.'
-        elif status == 2:
-            text = 'Minimum one hard disc is defect! Check it with: "cat /proc/mdstat"'
-        elif status == 3:
-            text = "I'am unsure about your disks. Please check your raid and hard discs by your self."
-        elif status == 4:
-            text = 'Raid Guard demon is active now.'
-            subj = 'Raid Guard Status'
-        
-        m = Mail(self.mail)
-        m.create(subj=subj,message=text,recipients=self.mail['recipient_list'])
-        m.send()
-
-
-class Mail():
-    def __init__(self,data_dict):
-        """
-        data_dict={
-        'mail_from':'mail@yourdomain.net',
-        'host_user':'your_mail_host_username',
-        'host_pass':'your_passw',
-        'host_smtp':'smtp.domain.net',
-        }
-        """
-        self.data = data_dict
-        self.msg = None # for mime text instance
-        self.recipients = []
-        
-    def create(self,subj,message,recipients):
-        if not type(recipients) == list:
-            self.recipients = [recipients,]
-        else:
-            self.recipients = recipients
-        
-        self.msg = MIMEText(message.encode('utf-8'), 'plain', 'UTF-8')
-        self.msg['Subject'] = subj
-        self.msg['From'] = self.data['mail_from']
-        self.msg['To'] = ",".join(self.recipients)
-
-    def send(self):
-        # Smtp login
-        s = smtplib.SMTP(self.data['host_smtp'])
-        s.login(self.data['host_user'],self.data['host_pass'])
-        
-        # Sending the Mail
-        try:
-            # Send mail with the sender address of the mail form user.
-            s.sendmail(self.msg['From'], self.recipients, self.msg.as_string())
-            s.quit()
-            
-        except smtplib.SMTPSenderRefused as e:
-            # Ups that does not worked at all. Now we use 
-            # a different sender address.
-            # We try to send with our own host user email 
-            # address as sender address.
-            # We do it because mail host services often do not allow 
-            # send an email with an unknown mail address.
-            
-            # we can do it only if user name is an email address
-            if '@' in self.data['host_user']:
-                del self.msg['From']
-                self.msg['From'] = self.data['host_user'] # change the sender
-    
-                # and now sending the mail again
-                s.sendmail(self.msg['From'], self.recipients, self.msg.as_string())
-                s.quit()
-                
-                logging.warning("""
-                                Fall back: Alternate mail sending routine
-                                (changed your sender address) successful executed!
-                                probably your mail host don't allow to send an
-                                email with an unknown mail address
-                            """)
-            else:
-                logging.warning("""
-                                probably your mail host don't allow to send an
-                                email with an unknown mail address
-                                """)
-                raise smtplib.SMTPSenderRefused(e,'','')
-
-
-    
-class TestMail(unittest.TestCase):
-    def setUp(self):
-        data_dict={
-            'mail_from':'m@yourd.eu',
-            'host_user':'your_mail_host_username',
-            'host_pass':'your_passw',
-            'host_smtp':'smtp.domain.net',
-            }
-        self.mail = Mail(data_dict)
-    
-    def test_mimetext_instance(self):
-        self.mail.create(subj='a subject',
-                         message=' a message',
-                         recipients= ['1@mm.eu', '2@mm.eu']
-                         )
-        self.assertEqual(self.mail.msg['Subject'], 'a subject')
-        self.assertEqual(self.mail.msg['From'], 'm@yourd.eu')
-        self.assertEqual(type(self.mail.msg['To']), type(''))
-        self.assertEqual(self.mail.msg['To'], '1@mm.eu,2@mm.eu')
-        
-    def test_send(self):
-        self.assertRaises(smtplib.SMTPAuthenticationError, self.mail.send)
-
-
-class TestGuard(unittest.TestCase):
-    def setUp(self):
-        d = {'value':'some dict'}
-        self.g = Guard(d)
-        self.pos = """2096064 blocks [2/2] [UU]
-        active raid1 sdb1[1] sda1[0]"""
-        self.neg = """active raid1 sda4[0] sdb4[1](F)
-        1822442815 blocks super 1.2 [2/1] [U_]"""
-        self.neg2 = """2096064 blocks [2/2] [UU]
-        active raid1 sdb1[1] sda1[0]
-        active raid1 sda4[0] sdb4[1](F)
-        1822442815 blocks super 1.2 [2/1] [U_]"""
-        self.non = """Personalities : 
-        unused devices: <none>"""
-        
-    def test_positive(self):
-        self.assertEqual(1, self.g._get_status(self.pos))
-        
-    def test_negative(self):
-        self.assertEqual(2, self.g._get_status(self.neg))
-        self.assertEqual(2, self.g._get_status(self.neg2))
-        
-    def test_non(self):
-        self.assertEqual(3, self.g._get_status(self.non))
-        
-
-if __name__ == '__main__':
-    DEBUG = True
-    
-    if not DEBUG:
-        args = ('start', 'stop', 'status', 'help', 'test')
-        app_name = os.path.basename(__file__)
-        d = Deiman("/tmp/%s.pid" % app_name)
-        if len(sys.argv) == 1 or sys.argv[1] not in args:
-            print("Usage: %s %s" % (app_name,list(args)))
-            sys.exit(2)
-        opt = sys.argv[1]
-        
-        if opt == 'start':
-            d.start()
-        elif opt== 'stop':
-            d.stop()
-            sys.exit(0)
-        elif opt == 'status':
-            d.status()
-            sys.exit(0)
-        elif opt == 'test':
-            run_test()
-            sys.exit()
-        elif opt == 'help':
-            print('no help jet')
-            sys.exit()
-     
-    mail_param = {
-            'host_smtp':'smtp.gmx.net',
-            'host_user':'catapela@gmx.net',
-            #'host_smtp':'smtp.dd24.net',
-            #'host_user':'catforge@catgrab.eu',
-            'host_pass':'court3001x',
-            'recipient_list':['mail@catgrab.eu',],
-            'mail_from':'raid_guard@bitzeit.eu',
-            }
-    
-    if DEBUG:
-        ini_file = '%s/raid_guard.ini' % os.environ['HOME']
-    else:
-        ini_file = None
-    
-    g = Guard(mail_dict=mail_param,ini_path=ini_file)
-    g.start_daemon()
-    
-    
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+# This Python file uses the following encoding: utf-8
+
+
+from setuptools import setup, find_packages
+from glob import glob
+import os
+
+# strings
+lib_path = '/usr/share/raid_guard'
+
+# Get description from Readme file
+readme_file = os.path.join(os.path.dirname(__file__), 'README.rst')
+long_description = open(readme_file).read()
+
+setup(  
+    name='raid-guard',
+    version='0.1.3',
+    description='raid hard disc monitoring daemon for linux servers',
+    long_description=long_description,
+    author='Andreas Fritz',
+    author_email='raid_guard@bitzeit.eu',
+    url='http://www.sources.e-blue.eu/',
+    download_url='https://pypi.python.org/pypi',
+    packages = find_packages(),
+    entry_points={'console_scripts':['raid_guard=raid_guard:main'],},
+    include_package_data=True,
+    data_files=[
+                (lib_path, glob('raid_guard.ini')),
+                (lib_path, glob('README.rst')),
+                (lib_path, glob('LICENSE')),
+                ],
+    keywords="raid hard-disk server monitoring daemon",
+    classifiers=[
+                'Development Status :: 3 - Alpha',
+                'License :: OSI Approved :: MIT License',
+                'Operating System :: Unix',
+                'Programming Language :: Python :: 2.7',
+                'Environment :: Console',
+                'Natural Language :: English',
+                'Intended Audience :: System Administrators',
+                'Topic :: System :: Networking :: Monitoring',
+                'Topic :: System :: Networking :: Monitoring :: Hardware Watchdog',
+                'Topic :: System :: Systems Administration',
+                ],
+    install_requires = ['deiman','iniparse'],
+    )