summaryrefslogtreecommitdiff
path: root/debian/patches/0110-syslog.diff
blob: ceda4ae07673b6402b6937754ca55214b2b26c43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Description: add syslog messages on errors
Author: Jörg Frings-Fürst <debian@jffwebhosting.net>
Forwarded: via mail
Last-Update: 2014-05-22
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: trunk/mwc.py
===================================================================
--- trunk.orig/mwc.py
+++ trunk/mwc.py
@@ -19,6 +19,7 @@ import os
 import sys
 import getopt
 import traceback
+import syslog
 
 import subprocess
 
@@ -225,25 +226,28 @@ def sendmail(receiver, subject, content,
         # initialize session once, not each time this method gets called
         #
         # add try / except to open mailsession
-        #
+	#
+	
         try:
-    		if mailsession is None:
-            		mailsession = smtplib.SMTP(config.smtphost, config.smtpport)
-            		if config.useTLS:
-                    		mailsession.ehlo()
-                    		mailsession.starttls()
-            		mailsession.login(config.smtpusername, config.smtppwd)
-        #
+                if mailsession is None:
+                        mailsession = smtplib.SMTP(config.smtphost, config.smtpport)
+                        if config.useTLS:
+                                mailsession.ehlo()
+                                mailsession.starttls()
+                        mailsession.login(config.smtpusername, config.smtppwd)
+        except:
+                print('Error: Open smtp-session')
+                syslog.syslog(syslog.LOG_ERR, 'can not open smtp session')
+                exit(4)
+	#
         # add try / except to send mail
         #
+        try:
+                mailsession.sendmail(config.sender, receiver.split(','), mail.as_string())
         except:
-    		print('Error: Open smtp-session')
-    		exit(4)
-    	try:
-    		mailsession.sendmail(config.sender, receiver.split(','), mail.as_string())
-        except:
-    		print('Error: sendmail')
-    		exit(5)
+                print('Error: sendmail')
+                syslog.syslog(syslog.LOG_ERR, 'error on sendmail')
+                exit(5)
 
 # returns a list of all content that is stored locally for a specific site
 def getFileContents(shortname):
@@ -330,7 +334,11 @@ if __name__ == "__main__":
 
         configMod = '/etc/mwc/mwc-config'
         dryrun = None
-
+        
+        #
+        # add syslog open
+        #
+        syslog.openlog()
         try:
                 opts, args = getopt.getopt(sys.argv[1:], 'hc:d:', ['help', 'config=', 'dry-run='])
         except getopt.GetoptError:
@@ -355,11 +363,13 @@ if __name__ == "__main__":
             config = importlib.import_module(fullname)
         except: 
             print('Error: loading config')
+            syslog.syslog(syslog.LOG_ERR, 'can not found / load mwc-config')
             sys.exit(2)
         try:
             os.chdir(config.datadir)
         except: 
             print('Error: datadir not found')
+            syslog.syslog(syslog.LOG_ERR, 'datadir not found')
             sys.exit(3)
     
         if dryrun:
@@ -381,3 +391,5 @@ if __name__ == "__main__":
                         mailsession.quit()
                         mailsession = None
 
+        syslog.closelog()
+	
\ No newline at end of file