from common import PluginType
from yapsy.IPlugin import IPlugin
import requests
import yaml
import logging


class ReportExporter(IPlugin):

    category = PluginType.POSTPROCESS
    id = "report_exporter"

    def __init__(self):
        self.__log = logging.getLogger(__name__)

    def setConf(self, conf):
        self.__conf = conf

    def setDb(self, db):
        self.__db = db

    def setJournal(self, journal):
        pass

    def process(self):
        self.__log.info("Preparing report")

        #prepare YAML payload
        payload = yaml.dump(self.__db.create_report_payload())
        self.__log.info("Payload size: " + str(len(payload)))

        if payload is not None:
            #DELETE request on /data
            if self.__conf.getProperty('cleanreport'):
                url = self.__conf.getProperty('report') + '/data'
                requests.delete(url)

            #POST request on /data
            requests.post(url, data={'payload' : payload})
        else:
            self.__log.error("Reporting failed")

@@ -701,32 +701,56 @@
     
-#DELETE reques
+if self.__conf.getProperty('report') is no
 t 
+N
 on
- /data
+e
 %0A   
@@ -750,34 +750,41 @@
 one%0A            
-if
+    url =
  self.__conf.get
@@ -797,21 +797,16 @@
 ty('
-clean
 report')
 :%0A  
@@ -801,17 +801,26 @@
 report')
-:
+ + '/data'
 %0A       
@@ -820,37 +820,75 @@
                 
-url =
+#DELETE request on /data%0A                if
  self.__conf.get
@@ -893,32 +893,37 @@
 etProperty('
+clean
 report')
  + '/data'%0A 
@@ -906,35 +906,30 @@
 leanreport')
- + '/data'%0A
+:%0A    
             
@@ -953,17 +953,20 @@
 te(url)%0A
-%0A
+    
         
@@ -984,32 +984,36 @@
 equest on /data%0A
+    
             requ

Fix report exporter