Revision 14d30d82 src/host/Host.cc

View differences:

src/host/Host.cc
69 69
    "last_mon_time INTEGER, uid INTEGER, gid INTEGER, owner_u INTEGER, "
70 70
    "group_u INTEGER, other_u INTEGER, UNIQUE(name))";
71 71

  
72

  
73
const char * Host::monit_table = "host_monitoring";
74

  
75
const char * Host::monit_db_names = "hid, last_mon_time, body";
76

  
77
const char * Host::monit_db_bootstrap = "CREATE TABLE IF NOT EXISTS "
78
    "host_monitoring (hid INTEGER, last_mon_time INTEGER, body TEXT, "
79
    "PRIMARY KEY(hid, last_mon_time))";
72 80
/* ------------------------------------------------------------------------ */
73 81
/* ------------------------------------------------------------------------ */
74 82

  
......
153 161
    goto error_generic;
154 162

  
155 163
error_generic:
156
    error_str = "Error inserting Group in DB.";
164
    error_str = "Error inserting Host in DB.";
157 165
error_common:
158 166
    return -1;
159 167
}
......
188 196
    return 0;
189 197
}
190 198

  
199
/* -------------------------------------------------------------------------- */
200
/* -------------------------------------------------------------------------- */
201

  
202
int Host::update_monitoring(SqlDB * db)
203
{
204
    ostringstream   oss;
205
    int             rc;
206

  
207
    string xml_body;
208
    string error_str;
209
    char * sql_xml;
210

  
211
    sql_xml = db->escape_str(to_xml(xml_body).c_str());
212

  
213
    if ( sql_xml == 0 )
214
    {
215
        goto error_body;
216
    }
217

  
218
    if ( validate_xml(sql_xml) != 0 )
219
    {
220
        goto error_xml;
221
    }
222

  
223
    oss << "DELETE FROM " << monit_table
224
        << " WHERE hid=" << oid
225
        << " AND last_mon_time < (" << last_monitored
226
        << " - " << HostPool::host_monitoring_history() << ")";
227

  
228
    db->exec(oss);
229

  
230
    oss.str("");
231
    oss << "INSERT INTO " << monit_table << " ("<< monit_db_names <<") VALUES ("
232
        <<          oid             << ","
233
        <<          last_monitored       << ","
234
        << "'" <<   sql_xml         << "')";
235

  
236
    db->free_str(sql_xml);
237

  
238
    rc = db->exec(oss);
239

  
240
    return rc;
241

  
242
error_xml:
243
    db->free_str(sql_xml);
244

  
245
    error_str = "could not transform the Host to XML.";
246

  
247
    goto error_common;
248

  
249
error_body:
250
    error_str = "could not insert the Host in the DB.";
251

  
252
error_common:
253
    oss.str("");
254
    oss << "Error updating Host monitoring information, " << error_str;
255

  
256
    NebulaLog::log("ONE",Log::ERROR, oss);
257

  
258
    return -1;
259
}
260

  
261
/* -------------------------------------------------------------------------- */
262
/* -------------------------------------------------------------------------- */
263

  
264
int Host::clean_monitoring(SqlDB * db)
265
{
266
    ostringstream   oss;
267
    int             rc;
268

  
269
    oss << "DELETE FROM " << monit_table << " WHERE hid=" << oid;
270

  
271
    rc = db->exec(oss);
272

  
273
    return rc;
274
}
275

  
191 276
/* ************************************************************************ */
192 277
/* Host :: Misc                                                             */
193 278
/* ************************************************************************ */

Also available in: Unified diff