første xml update
[virt-orchestrator.git] / vFLOWER / content / Workflows / uio / lib / log / error.workflow.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <workflow xmlns="http://vmware.com/vco/workflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://vmware.com/vco/workflow http://vmware.com/vco/workflow/Workflow-v4.xsd" root-name="item3" object-name="workflow:name=generic" id="2cdac1c6-1c4b-4fd4-aa62-a2736a71f7e7" version="1.0.4" api-version="3.1.0" allowed-operations="fve" icon-id="3938885e-2198-4f6d-a87b-6e65f3cb4a57" restartMode="1" resumeFromFailedMode="0">
3     <display-name>error</display-name>
4
5     <description>Looger error melding til email og database</description>
6
7     <position x="100.0" y="50.0"/>
8
9     <input>
10         <param name="message" type="string"/>
11     </input>
12
13     <attrib name="query" type="string" read-only="false">
14         <value encoded="n"/>
15         <description>sql error query</description>
16     </attrib>
17     <attrib name="rowsAffected" type="number" read-only="false">
18         <value encoded="n">__NULL__</value>
19         <description>The number of rows affected by the query</description>
20     </attrib>
21     <attrib name="mailto" type="string" read-only="false">
22         <value encoded="n">__NULL__</value>
23         <description>Default mailto parameter</description>
24     </attrib>
25     <attrib name="smtp_server" type="string" read-only="false">
26         <value encoded="n">__NULL__</value>
27         <description>Default SMTP server</description>
28     </attrib>
29     <attrib name="smtp_port" type="string" read-only="false">
30         <value encoded="n">__NULL__</value>
31         <description>Default SMTP port</description>
32     </attrib>
33     <attrib name="database" type="SQL:Database" read-only="false">
34         <value encoded="n">__NULL__</value>
35         <description>Default database</description>
36     </attrib>
37     <attrib name="state" type="string" read-only="false">
38         <value encoded="n">ERROR</value>
39         <description>Log state</description>
40     </attrib>
41     <attrib name="enable_mail" type="string" read-only="false">
42         <value encoded="n">false</value>
43         <description>If true, send email for all events</description>
44     </attrib>
45     <attrib name="vmPassword" type="SecureString" read-only="false">
46         <value encoded="n"/>
47     </attrib>
48
49     <workflow-item name="item0" type="end" end-mode="0">
50         <position x="684.5" y="99.95454545454544"/>
51     </workflow-item>
52
53     <workflow-item name="item1" out-name="item0" type="link" linked-workflow-id="028080808080808080808080808080809F808080013264596926189e8150e1493">
54         <display-name>Execute a custom query on a database</display-name>
55
56         <in-binding>
57             <bind name="database" type="SQL:Database" export-name="database">
58                 <description>The database to use for the query</description>
59             </bind>
60             <bind name="query" type="string" export-name="query">
61                 <description>The query to execute</description>
62             </bind>
63         </in-binding>
64
65         <out-binding>
66             <bind name="rowsAffected" type="number" export-name="rowsAffected">
67                 <description>The number of rows affected by the query</description>
68             </bind>
69         </out-binding>
70
71         <description>Executes a custom query on a specified database and returns the number of affected rows. You can run the workflow to update, delete, and insert queries.</description>
72
73         <position x="504.5" y="55.40909090909091"/>
74     </workflow-item>
75
76     <workflow-item name="item2" out-name="item4" type="task">
77         <display-name>Generate SQL error string</display-name>
78
79         <script encoded="false">
80 //get name of the current workflow
81 var wname = workflow.rootWorkflow.name;
82
83 // System.debug("Root Workflow "+WorkFlow);
84
85
86 //var date = System.getDateFromFormat(Date);
87
88 var currentdate = new Date();
89 var date = System.formatDate(currentdate, 'yyyy-MM-dd HH:mm:ss');
90
91 // Get current user 
92 try {
93         var user = Server.getCredential().username;
94 }
95 catch(err) {
96         // Not able to get user, setting vCAC
97         user = 'vCAC';
98 }
99
100
101
102 var dbmesg = message.replace(/[`'']/g,'"');
103 var wname = wname.replace(/[`'']/g,'"');
104 query="insert into log "
105         +"(log_source, log_date, log_level, log_line, log_category, log_mesg)"
106         +" values "
107         +"('"+user+"@Orchestrator', '"+date+"', '"+state+"', 0, '"+wname+"', '" + dbmesg + "');";
108
109 if (enable_mail == "true") {
110         var mail = new EmailMessage() ;
111         mail.fromAddress='virtprov@usit.uio.no';
112         mail.toAddress=mailto;
113         mail.subject=state+" from "+user+"@Orchestrator/"+wname+"";
114         mail.smtpPort=smtp_port;
115         mail.smtpHost=smtp_server;
116
117
118         var body=state+" message from Vmware Orchestrator\n"
119                 +"User "+user+" has run a workflow which generated "+state+"\n"
120                 +"\n"
121                 +state+" message: \n"
122                 +message+"";
123
124         mail.addMimePart(body)
125         mail.sendMessage();
126 }
127         </script>
128
129         <in-binding>
130             <bind name="enable_mail" type="string" export-name="enable_mail">
131                 <description>If true, send email for all events</description>
132             </bind>
133             <bind name="mailto" type="string" export-name="mailto">
134                 <description>Default mailto parameter</description>
135             </bind>
136             <bind name="message" type="string" export-name="message"/>
137             <bind name="smtp_port" type="string" export-name="smtp_port">
138                 <description>Default SMTP port</description>
139             </bind>
140             <bind name="smtp_server" type="string" export-name="smtp_server">
141                 <description>Default SMTP server</description>
142             </bind>
143             <bind name="state" type="string" export-name="state">
144                 <description>Log state</description>
145             </bind>
146         </in-binding>
147
148         <out-binding>
149             <bind name="query" type="string" export-name="query">
150                 <description>The query to execute</description>
151             </bind>
152         </out-binding>
153
154         <position x="364.5" y="55.40909090909091"/>
155     </workflow-item>
156
157     <workflow-item name="item3" out-name="item2" type="link" linked-workflow-id="1f0fc470-006c-4c15-a3b9-95e2e7540f22">
158         <display-name>global_parameters</display-name>
159
160         <in-binding/>
161
162         <out-binding>
163             <bind name="mailto" type="string" export-name="mailto"/>
164             <bind name="smtp_server" type="string" export-name="smtp_server"/>
165             <bind name="smtp_port" type="string" export-name="smtp_port"/>
166             <bind name="database" type="SQL:Database" export-name="database"/>
167             <bind name="vmPassword" type="SecureString" export-name="vmPassword"/>
168         </out-binding>
169
170         <position x="204.5" y="55.40909090909091"/>
171     </workflow-item>
172
173     <workflow-item name="item4" out-name="item1" type="condition" alt-out-name="item0" comparator="0">
174         <display-name>Decision</display-name>
175
176         <script encoded="false">
177 //Generated by the system, cannot be edited
178 return (database  != null ) ;
179         </script>
180
181         <in-binding>
182             <bind name="database" type="SQL:Database" export-name="database"/>
183         </in-binding>
184         <condition name="database" type="SQL:Database" comparator="0" label="null"/>
185
186         <position x="425.0" y="118.13636363636363"/>
187     </workflow-item>
188
189     <presentation>
190         <p-param name="message">
191             <desc>message</desc>
192         </p-param>
193     </presentation>
194 </workflow>