| 1 |
#include "lime-perf.h" |
|---|
| 2 |
#include "alarmprop_gui.h" |
|---|
| 3 |
#include <qaction.h> |
|---|
| 4 |
#include <qwidgetstack.h> |
|---|
| 5 |
#include <qlayout.h> |
|---|
| 6 |
#include <qlabel.h> |
|---|
| 7 |
#include <qscrollview.h> |
|---|
| 8 |
#include <qvbox.h> |
|---|
| 9 |
#include <qtable.h> |
|---|
| 10 |
#include <qmap.h> |
|---|
| 11 |
#include <qradiobutton.h> |
|---|
| 12 |
#include <qcheckbox.h> |
|---|
| 13 |
#include <qcombobox.h> |
|---|
| 14 |
#include <qpushbutton.h> |
|---|
| 15 |
#include <qlineedit.h> |
|---|
| 16 |
#include <qsizepolicy.h> |
|---|
| 17 |
#include <qtabwidget.h> |
|---|
| 18 |
#include <qmessagebox.h> |
|---|
| 19 |
#include <qobject.h> |
|---|
| 20 |
#include <wbemfiledialog.hpp> |
|---|
| 21 |
#include "alarmbase.h" |
|---|
| 22 |
#include "renamecond.h" |
|---|
| 23 |
#include <map> |
|---|
| 24 |
#include <string> |
|---|
| 25 |
#include "corefile/SensorManager.h" |
|---|
| 26 |
#include "PolicyRule.h" |
|---|
| 27 |
#include "corefile/PolicyManager.h" |
|---|
| 28 |
#include <wbemutils.hpp> |
|---|
| 29 |
|
|---|
| 30 |
#define LIMEMONITOR_GROUPNAME "lime-monitor_group" |
|---|
| 31 |
class Sensor; |
|---|
| 32 |
QStringList AlarmPropGUI::sc=QStringList::split(",","Processor,Process,Disk,FileSystem,NetWork,Memory"); |
|---|
| 33 |
QStringList AlarmPropGUI::prop[]={ |
|---|
| 34 |
QStringList::split(",","InterruptsRate,ContextSwitch,ContextSwitchRate," |
|---|
| 35 |
"ProcessorTimePercentage,SystemTimePercentage,UserTimePercentage,ProcessCount"), |
|---|
| 36 |
QStringList::split(",","CpuTime,UserTime,CumulateCpuTime,CumulateUserTime,Swap,MinorFault," |
|---|
| 37 |
"CumulateMinorFault,MajorFault,CumulateMajorFault,RealText,RealData,RealStack," |
|---|
| 38 |
"VirtualText,VirtualData,VirtualStack,VirtualSharedMemory,VirtualLib,VirtualLock," |
|---|
| 39 |
"Resident,DirtyPage,VirtualMemoryMappedFileSize,CpuTimeDeadChildren,SystemTimeDeadChildren"), |
|---|
| 40 |
QStringList::split(",","BlocksRead,BlocksWrite,SectorsRead,SectorsWrite," |
|---|
| 41 |
"BlocksReadRate,BlocksWriteRate,SectorsReadRate,SectorsWriteRate"), |
|---|
| 42 |
QStringList::split(",","FreeInodes,TotalInodes,FSReservedInodes," |
|---|
| 43 |
"FSReservedCapacity,BlockSize,FileSystemSize,AvailableSpace,MaxFileNameLength,NumberOfFiles,PersistenceType"), |
|---|
| 44 |
QStringList::split(",","PacketsTransmitted,PacketsReceived,BytesTransmitted," |
|---|
| 45 |
"BytesReceived,FCSErrors,CarrierSenseErrors,FIFOTransmittedErrors,FIFOReceivedErrors,TransmittedCollisions," |
|---|
| 46 |
"TransmittedErrors,ReceivedErrors,MulticastReceived,CompressedBytesReceived,CompressedBytesTransmitted," |
|---|
| 47 |
"DropedErrorsReceived,DropedErrorsTransmitted,PacketsTransmittedRate,PacketsReceivedRate," |
|---|
| 48 |
"BytesTransmittedRate,BytesReceivedRate"), |
|---|
| 49 |
QStringList::split(",","Buffer,Cache,Free,FreePhysicalMemory,FreeSwap,Used," |
|---|
| 50 |
"UsedPhysicalMemory,UsedSwap,PageIn,PageInRate,PageOut,PageOutRate,SwapIn,SwapInRate,SwapOut,SwapOutRate")}; |
|---|
| 51 |
|
|---|
| 52 |
/* |
|---|
| 53 |
* Constructs a Form1 as a child of 'parent', with the |
|---|
| 54 |
* name 'name' and widget flags set to 'f'. |
|---|
| 55 |
*/ |
|---|
| 56 |
AlarmPropGUI::AlarmPropGUI( QWidget* parent, const char* name, bool modal, WFlags fl ) |
|---|
| 57 |
: AlarmPropGUIBase( parent, name, modal, fl ) |
|---|
| 58 |
{ |
|---|
| 59 |
this->ag=(AlarmBase*)parent; |
|---|
| 60 |
|
|---|
| 61 |
for(std::map<std::string,Sensor*>::iterator it=ag->sm->AllSensorList.begin();it!=ag->sm->AllSensorList.end();it++) |
|---|
| 62 |
{ |
|---|
| 63 |
QString tmp((*it).second->GetClassType().c_str()); |
|---|
| 64 |
if(tmp=="Processor") sl[0].append(QString::fromUtf8((*it).first.c_str())); |
|---|
| 65 |
else if(tmp=="Process") sl[1].append(QString::fromUtf8((*it).first.c_str())); |
|---|
| 66 |
else if(tmp=="Disk") sl[2].append(QString::fromUtf8((*it).first.c_str())); |
|---|
| 67 |
else if(tmp=="FileSystem") sl[3].append(QString::fromUtf8((*it).first.c_str())); |
|---|
| 68 |
else if(tmp=="NetWork") sl[4].append(QString::fromUtf8((*it).first.c_str())); |
|---|
| 69 |
else if(tmp=="Memory") sl[5].append(QString::fromUtf8((*it).first.c_str())); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
//sc<<"Processor"<<"Process"<<"Disk"<<"FileSystem"<<"NetWork"<<"Memory"; |
|---|
| 73 |
wl<<_("equals to")<<_("not equals to")<<_("greater than")<<_("less than")<<_("not less than")<<_("not greater than"); |
|---|
| 74 |
/* |
|---|
| 75 |
prop[0]<<"InterruptsRate"<<"ContextSwitch"<<"ContextSwitchRate" |
|---|
| 76 |
<<"ProcessorTimePercentage"<<"SystemTimePercentage"<<"UserTimePercentage"<<"processCount"; |
|---|
| 77 |
prop[1]<<"CpuTime"<<"UserTime"<<"CumulateCpuTime"<<"CumulateUserTime"<<"Swap"<<"MinorFault" |
|---|
| 78 |
<<"CumulateMinorFault"<<"MajorFault"<<"CumulateMajorFault"<<"RealText"<<"RealData"<<"RealStack" |
|---|
| 79 |
<<"VirtualText"<<"VirtualData"<<"VirtualStack"<<"VirtualSharedMemory"<<"VirtualLib"<<"VirtualLock" |
|---|
| 80 |
<<"Resident"<<"DirtyPage"<<"VirtualMemoryMappedFileSize"<<"CpuTimeDeadChildren"<<"SystemTimeDeadChildren"; |
|---|
| 81 |
prop[2]<<"BlocksRead"<<"BlocksWrite"<<"SectorsRead"<<"SectorsWrite"<<"BlocksReadRate"<<"BlocksWriteRate" |
|---|
| 82 |
<<"SectorsReadRate"<<"SectorsWriteRate"; |
|---|
| 83 |
prop[3]<<"FreeInodes"<<"TotalInodes"<<"FSReservedInodes"<<"FSReservedCapacity"<<"BlockSize"<<"FileSystemSize" |
|---|
| 84 |
<<"AvailableSpace"<<"MaxFileNameLength"<<"NumberOfFiles"<<"PersistenceType"; |
|---|
| 85 |
prop[4]<<"PacketsTransmitted"<<"PacketsReceived"<<"BytesTransmitted"<<"BytesReceived"<<"FCSErrors" |
|---|
| 86 |
<<"CarrierSenseErrors"<<"FIFOTransmittedErrors"<<"FIFOReceivedErrors"<<"TransmittedCollisions" |
|---|
| 87 |
<<"TransmittedErrors"<<"ReceivedErrors"<<"MulticastReceived"<<"CompressedBytesReceived" |
|---|
| 88 |
<<"CompressedBytesTransmitted"<<"DropedErrorsReceived"<<"DropedErrorsTransmitted"<<"PacketsTransmittedRate" |
|---|
| 89 |
<<"PacketsReceivedRate"<<"BytesTransmittedRate"<<"BytesReceivedRate"; |
|---|
| 90 |
prop[5]<<"Buffer"<<"Cache"<<"Free"<<"FreePhysicalMemory"<<"FreeSwap"<<"Used"<<"UsedPhysicalMemory"<<"UsedSwap"<<"PageIn" |
|---|
| 91 |
<<"PageInRate"<<"PageOut"<<"PageOutRate"<<"SwapIn"<<"SwapInRate"<<"SwapOut"<<"SwapOutRate"; |
|---|
| 92 |
*/ |
|---|
| 93 |
|
|---|
| 94 |
/* |
|---|
| 95 |
QHBoxLayout * svlayout = new QHBoxLayout(frame6,1, 1,"Layout"); |
|---|
| 96 |
sv=new QScrollView(frame6,"sv" ); |
|---|
| 97 |
sv->setVScrollBarMode(QScrollView::Auto); |
|---|
| 98 |
svlayout->addWidget(sv, 0, 0 ); |
|---|
| 99 |
sv->setVScrollBarMode(QScrollView::AlwaysOn); |
|---|
| 100 |
|
|---|
| 101 |
view=sv->viewport(); |
|---|
| 102 |
view->setPaletteBackgroundColor(parent->paletteBackgroundColor()); |
|---|
| 103 |
|
|---|
| 104 |
vbox= new QVBox(view); |
|---|
| 105 |
sv->addChild(vbox); |
|---|
| 106 |
|
|---|
| 107 |
hbox= new QHBox(vbox); |
|---|
| 108 |
initSimpleCondition=new SimpleCondition(this, hbox,"sc"); |
|---|
| 109 |
|
|---|
| 110 |
initSimpleCondition->SetEnabled(false); |
|---|
| 111 |
|
|---|
| 112 |
simpleConditionList.setAutoDelete(false); |
|---|
| 113 |
pushButtonSD->setEnabled(false); |
|---|
| 114 |
// simpleConditionList.append(newSimpleCondition); |
|---|
| 115 |
|
|---|
| 116 |
pushButtonSimple->hide(); |
|---|
| 117 |
*/ |
|---|
| 118 |
widgetStack1->raiseWidget(0); |
|---|
| 119 |
|
|---|
| 120 |
// connect((QObject*)pushButtonSimple,SIGNAL(clicked()),this,SLOT(simpleWidget())); |
|---|
| 121 |
// connect((QObject*)pushButtonAdvance,SIGNAL(clicked()),this,SLOT(advanceWidget())); |
|---|
| 122 |
|
|---|
| 123 |
connect((QObject*)pushButtonSA,SIGNAL(clicked()),this,SLOT(newCondition())); |
|---|
| 124 |
connect((QObject*)pushButtonSD,SIGNAL(clicked()),this,SLOT(deleteChilds())); |
|---|
| 125 |
|
|---|
| 126 |
connect((QObject*)pushButtonNew,SIGNAL(clicked()),this,SLOT(newTableItem())); |
|---|
| 127 |
connect((QObject*)pushButtonDelete,SIGNAL(clicked()),this,SLOT(removeCurrentTableItem())); |
|---|
| 128 |
connect((QObject*)table1,SIGNAL(valueChanged ( int , int )),this,SLOT(advanceRefresh(int ,int ))); |
|---|
| 129 |
connect((QObject*)ok_btn,SIGNAL(clicked()),this,SLOT(commit())); |
|---|
| 130 |
connect((QObject*)cancel_btn,SIGNAL(clicked()),this,SLOT(close())); |
|---|
| 131 |
connect((QObject*)apply_btn,SIGNAL(clicked()),this,SLOT(apply())); |
|---|
| 132 |
//remove away this function |
|---|
| 133 |
//connect((QObject*)table1,SIGNAL(doubleClicked ( int, int, int, const QPoint&)),this, |
|---|
| 134 |
// SLOT(renameRow( int, int, int, const QPoint &))); |
|---|
| 135 |
connect((QObject*)smtp_cb,SIGNAL(toggled(bool)),TextLabel10,SLOT(setEnabled(bool))); |
|---|
| 136 |
connect((QObject*)smtp_cb,SIGNAL(toggled(bool)),smtp_param_le,SLOT(setEnabled(bool))); |
|---|
| 137 |
connect((QObject*)log_cb,SIGNAL(toggled(bool)),TextLabel10_2,SLOT(setEnabled(bool))); |
|---|
| 138 |
connect((QObject*)log_cb,SIGNAL(toggled(bool)),log_param_le,SLOT(setEnabled(bool))); |
|---|
| 139 |
connect((QObject*)log_cb,SIGNAL(toggled(bool)),log_file_btn,SLOT(setEnabled(bool))); |
|---|
| 140 |
connect((QObject*)log_file_btn,SIGNAL(clicked()),this,SLOT(selectFile())); |
|---|
| 141 |
connect((QObject*)command_cb,SIGNAL(toggled(bool)),TextLabel10_3,SLOT(setEnabled(bool))); |
|---|
| 142 |
connect((QObject*)command_cb,SIGNAL(toggled(bool)),command_param_le,SLOT(setEnabled(bool))); |
|---|
| 143 |
connect((QObject*)radioButtonAnd,SIGNAL(toggled(bool)),this,SLOT(showCondition())); |
|---|
| 144 |
//show(); |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
/* |
|---|
| 148 |
* Destroys the object and frees any allocated resources |
|---|
| 149 |
*/ |
|---|
| 150 |
AlarmPropGUI::~AlarmPropGUI() |
|---|
| 151 |
{ |
|---|
| 152 |
// no need to delete child widgets, Qt does it all for us |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
/* |
|---|
| 156 |
* Sets the strings of the subwidgets using the current |
|---|
| 157 |
* language. |
|---|
| 158 |
*/ |
|---|
| 159 |
void AlarmPropGUI::languageChange() |
|---|
| 160 |
{ |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
void AlarmPropGUI::simpleWidget() |
|---|
| 164 |
{ |
|---|
| 165 |
widgetStack1->raiseWidget(1); |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
void AlarmPropGUI::advanceWidget() |
|---|
| 169 |
{ |
|---|
| 170 |
widgetStack1->raiseWidget(0); |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
void AlarmPropGUI::newCondition(int row) |
|---|
| 174 |
{ |
|---|
| 175 |
SimpleCondition *newSimpleCondition; |
|---|
| 176 |
if(simpleConditionList.count()==0) |
|---|
| 177 |
{ |
|---|
| 178 |
initSimpleCondition->SetEnabled(true); |
|---|
| 179 |
simpleConditionList.append(initSimpleCondition); |
|---|
| 180 |
newSimpleCondition=initSimpleCondition; |
|---|
| 181 |
} |
|---|
| 182 |
else |
|---|
| 183 |
{ |
|---|
| 184 |
SimpleCondition *sc=simpleConditionList.first(); |
|---|
| 185 |
for(int i=simpleConditionList.count();i>0;i--) |
|---|
| 186 |
{ |
|---|
| 187 |
//sc->hideAddButton(); |
|---|
| 188 |
sc=simpleConditionList.next(); |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
hbox= new QHBox(vbox); |
|---|
| 193 |
newSimpleCondition=new SimpleCondition(this, hbox,"sc"); |
|---|
| 194 |
// QScrollBar * vsb=sv->verticalScrollBar(); |
|---|
| 195 |
// vsb->setValue(vsb->value()); |
|---|
| 196 |
hbox->show(); |
|---|
| 197 |
|
|---|
| 198 |
simpleConditionList.append(newSimpleCondition); |
|---|
| 199 |
// connect((QObject*)newSimpleCondition->pushButtonAdd,SIGNAL(clicked()),this,SLOT(newCondition())); |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
if(row!=-1) |
|---|
| 203 |
{ |
|---|
| 204 |
newSimpleCondition->setConditionName(table1->verticalHeader()->label(row)); |
|---|
| 205 |
newSimpleCondition->setClass(((QComboTableItem*)table1->item(row,0))->currentItem()); |
|---|
| 206 |
newSimpleCondition->refresh(((QComboTableItem*)table1->item(row,0))->currentItem()); |
|---|
| 207 |
newSimpleCondition->setInst(((QComboTableItem*)table1->item(row,1))->currentItem()); |
|---|
| 208 |
newSimpleCondition->setProperty(((QComboTableItem*)table1->item(row,2))->currentItem()); |
|---|
| 209 |
newSimpleCondition->setIf(((QComboTableItem*)table1->item(row,3))->currentItem()); |
|---|
| 210 |
newSimpleCondition->setValue(table1->item(row,4)->text()); |
|---|
| 211 |
} |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
void AlarmPropGUI::deleteChild(SimpleCondition *sc) |
|---|
| 215 |
{ |
|---|
| 216 |
int p=simpleConditionList.find(sc); |
|---|
| 217 |
if(p==-1) return; |
|---|
| 218 |
unsigned int i=p; |
|---|
| 219 |
if(simpleConditionList.count()>1) |
|---|
| 220 |
{ |
|---|
| 221 |
//if(i==simpleConditionList.count()-1) { simpleConditionList.at(i-1)->showAddButton();} |
|---|
| 222 |
QWidget * box=sc->box; |
|---|
| 223 |
delete simpleConditionList.at(i); |
|---|
| 224 |
simpleConditionList.remove(i); |
|---|
| 225 |
delete box; |
|---|
| 226 |
if(simpleConditionList.count()==1) |
|---|
| 227 |
{ |
|---|
| 228 |
initSimpleCondition=simpleConditionList.first(); |
|---|
| 229 |
initSimpleCondition->SetEnabled(true); |
|---|
| 230 |
} |
|---|
| 231 |
} |
|---|
| 232 |
else if(simpleConditionList.count()==1) |
|---|
| 233 |
{ |
|---|
| 234 |
initSimpleCondition->SetEnabled(false); |
|---|
| 235 |
unsigned int j=0; |
|---|
| 236 |
simpleConditionList.remove(j); |
|---|
| 237 |
} |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
void AlarmPropGUI::deleteChilds() |
|---|
| 241 |
{ |
|---|
| 242 |
for(int j=2;j>0;j--) |
|---|
| 243 |
{ |
|---|
| 244 |
for(int i=0;i<simpleConditionList.count();) |
|---|
| 245 |
{ |
|---|
| 246 |
if(simpleConditionList.at(i)->checkBoxS->isChecked()) |
|---|
| 247 |
{ |
|---|
| 248 |
deleteChild(simpleConditionList.at(i)); |
|---|
| 249 |
continue; |
|---|
| 250 |
} |
|---|
| 251 |
i++; |
|---|
| 252 |
} |
|---|
| 253 |
} |
|---|
| 254 |
setSDS(); |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
void AlarmPropGUI::setSDS() |
|---|
| 258 |
{ |
|---|
| 259 |
pushButtonSD->setEnabled(false); |
|---|
| 260 |
for(int i=0;i<simpleConditionList.count();i++) |
|---|
| 261 |
{ |
|---|
| 262 |
if(simpleConditionList.at(i)->checkBoxS->isChecked()) |
|---|
| 263 |
{ |
|---|
| 264 |
pushButtonSD->setEnabled(true); |
|---|
| 265 |
break; |
|---|
| 266 |
} |
|---|
| 267 |
} |
|---|
| 268 |
} |
|---|
| 269 |
|
|---|
| 270 |
void AlarmPropGUI::show_alarm(PolicyRule* rule) |
|---|
| 271 |
{ |
|---|
| 272 |
if(rule==NULL) |
|---|
| 273 |
{ |
|---|
| 274 |
newRule=true; |
|---|
| 275 |
this->rule=new PolicyRule(LIMEMONITOR_GROUPNAME); |
|---|
| 276 |
return; |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
newRule=false; |
|---|
| 280 |
this->rule=rule; |
|---|
| 281 |
|
|---|
| 282 |
name_le->setText(QString::fromUtf8(rule->GetName().c_str())); |
|---|
| 283 |
comments_le->setText(rule->GetComments().c_str()); |
|---|
| 284 |
//show the conditions and actions |
|---|
| 285 |
this->showAdvance(); |
|---|
| 286 |
this->setGroupConsults(); |
|---|
| 287 |
//this->showSimple(); |
|---|
| 288 |
this->showAction(); |
|---|
| 289 |
widgetStack1->raiseWidget(0); |
|---|
| 290 |
} |
|---|
| 291 |
|
|---|
| 292 |
void AlarmPropGUI::newTableItem(QString condition) |
|---|
| 293 |
{ |
|---|
| 294 |
QHeader * hheader=table1->verticalHeader(); |
|---|
| 295 |
conditionList.clear(); |
|---|
| 296 |
for(unsigned int j=0;j<table1->numRows();j++) |
|---|
| 297 |
{ |
|---|
| 298 |
conditionList << hheader->label(j); |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|
| 301 |
unsigned int i=table1->numRows(); |
|---|
| 302 |
table1->insertRows(i); |
|---|
| 303 |
|
|---|
| 304 |
QComboTableItem * classT=new QComboTableItem(table1,sc); |
|---|
| 305 |
table1->setItem( i, 0, classT); |
|---|
| 306 |
|
|---|
| 307 |
QComboTableItem * when=new QComboTableItem(table1,wl); |
|---|
| 308 |
table1->setItem( i, 3, when); |
|---|
| 309 |
if(condition.isEmpty()) |
|---|
| 310 |
{ |
|---|
| 311 |
|
|---|
| 312 |
QComboTableItem * inst=new QComboTableItem(table1,sl[0]); |
|---|
| 313 |
table1->setItem( i, 1, inst); |
|---|
| 314 |
QComboTableItem * propi=new QComboTableItem(table1,prop[0]); |
|---|
| 315 |
table1->setItem( i, 2, propi); |
|---|
| 316 |
classT->setCurrentItem(0); |
|---|
| 317 |
|
|---|
| 318 |
if(conditionList.size()>0) |
|---|
| 319 |
{ |
|---|
| 320 |
QString t=hheader->label(conditionList.size()); |
|---|
| 321 |
if(conditionList.findIndex(t)==-1) |
|---|
| 322 |
{ |
|---|
| 323 |
conditionList<<t; |
|---|
| 324 |
} |
|---|
| 325 |
else |
|---|
| 326 |
{ |
|---|
| 327 |
for(unsigned int j=1;;j++) |
|---|
| 328 |
{ |
|---|
| 329 |
if(conditionList.findIndex(QString::number(j))==-1) |
|---|
| 330 |
{ |
|---|
| 331 |
conditionList<<QString::number(j); |
|---|
| 332 |
break; |
|---|
| 333 |
} |
|---|
| 334 |
} |
|---|
| 335 |
} |
|---|
| 336 |
table1->setRowLabels(conditionList); |
|---|
| 337 |
} |
|---|
| 338 |
showCondition(); |
|---|
| 339 |
return; |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
QString conName=condition.section("\n",0,0); |
|---|
| 343 |
QString keyword=condition.section("\n",1,1); |
|---|
| 344 |
|
|---|
| 345 |
QString classType; |
|---|
| 346 |
QString instName; |
|---|
| 347 |
for(map<string,Sensor*>::iterator it=ag->sm->AllSensorList.begin();it!=ag->sm->AllSensorList.end();it++) |
|---|
| 348 |
{ |
|---|
| 349 |
if(keyword.stripWhiteSpace()==(*it).second->GetCOP().c_str()) |
|---|
| 350 |
{ |
|---|
| 351 |
classType=(*it).second->GetClassType().c_str(); |
|---|
| 352 |
instName= (*it).second->GetName().c_str(); |
|---|
| 353 |
break; |
|---|
| 354 |
} |
|---|
| 355 |
} |
|---|
| 356 |
int j=sc.findIndex(classType); |
|---|
| 357 |
if(j==-1) |
|---|
| 358 |
{ |
|---|
| 359 |
table1->removeRow(i); |
|---|
| 360 |
return ; |
|---|
| 361 |
} |
|---|
| 362 |
classT->setCurrentItem(j); |
|---|
| 363 |
|
|---|
| 364 |
QComboTableItem * inst=new QComboTableItem(table1,sl[j]); |
|---|
| 365 |
table1->setItem( i, 1, inst); |
|---|
| 366 |
QComboTableItem * propi=new QComboTableItem(table1,prop[j]); |
|---|
| 367 |
table1->setItem( i, 2, propi); |
|---|
| 368 |
|
|---|
| 369 |
int k=sl[j].findIndex(QString::fromUtf8(instName)); |
|---|
| 370 |
if(k!=-1) |
|---|
| 371 |
inst->setCurrentItem(k); |
|---|
| 372 |
else |
|---|
| 373 |
{ |
|---|
| 374 |
table1->removeRow(i); |
|---|
| 375 |
return; |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
keyword=condition.section("\n",2,2); |
|---|
| 379 |
k=prop[j].findIndex(keyword); |
|---|
| 380 |
if(k!=-1) |
|---|
| 381 |
propi->setCurrentItem(k); |
|---|
| 382 |
else |
|---|
| 383 |
{ |
|---|
| 384 |
table1->removeRow(i); |
|---|
| 385 |
return; |
|---|
| 386 |
} |
|---|
| 387 |
|
|---|
| 388 |
keyword=condition.section("\n",3,3); |
|---|
| 389 |
if(keyword=="==") when->setCurrentItem(0); |
|---|
| 390 |
else if(keyword=="!=") when->setCurrentItem(1); |
|---|
| 391 |
else if(keyword==">") when->setCurrentItem(2); |
|---|
| 392 |
else if(keyword=="<") when->setCurrentItem(3); |
|---|
| 393 |
else if(keyword==">=") when->setCurrentItem(4); |
|---|
| 394 |
else if(keyword=="<=") when->setCurrentItem(5); |
|---|
| 395 |
else |
|---|
| 396 |
{ |
|---|
| 397 |
table1->removeRow(i); |
|---|
| 398 |
return; |
|---|
| 399 |
} |
|---|
| 400 |
|
|---|
| 401 |
keyword=condition.section("\n",4,4); |
|---|
| 402 |
table1->setText(i,4,keyword); |
|---|
| 403 |
|
|---|
| 404 |
keyword=condition.section("\n",5,5); |
|---|
| 405 |
table1->setText(i,5,keyword); |
|---|
| 406 |
conditionList<<conName; |
|---|
| 407 |
// this->setGroupConsults(); |
|---|
| 408 |
showCondition(); |
|---|
| 409 |
} |
|---|
| 410 |
|
|---|
| 411 |
void AlarmPropGUI::removeCurrentTableItem() |
|---|
| 412 |
{ |
|---|
| 413 |
table1->removeRow(table1->currentRow()); |
|---|
| 414 |
conditionList.clear(); |
|---|
| 415 |
QHeader * hheader=table1->verticalHeader(); |
|---|
| 416 |
for(int i=0;i<table1->numRows();i++) |
|---|
| 417 |
{ |
|---|
| 418 |
conditionList << hheader->label(i); |
|---|
| 419 |
} |
|---|
| 420 |
this->setGroupConsults(); |
|---|
| 421 |
} |
|---|
| 422 |
|
|---|
| 423 |
void AlarmPropGUI::renameRow(int row, int , int , const QPoint & ) |
|---|
| 424 |
{ |
|---|
| 425 |
conditionList.clear(); |
|---|
| 426 |
QHeader * hheader=table1->verticalHeader(); |
|---|
| 427 |
for(int i=0;i<table1->numRows();i++) |
|---|
| 428 |
{ |
|---|
| 429 |
conditionList << hheader->label(i); |
|---|
| 430 |
} |
|---|
| 431 |
RenameCond * rc=new RenameCond(this,row); |
|---|
| 432 |
rc->exec(); |
|---|
| 433 |
delete rc; |
|---|
| 434 |
} |
|---|
| 435 |
|
|---|
| 436 |
void AlarmPropGUI::advanceRefresh(int row,int col) |
|---|
| 437 |
{ |
|---|
| 438 |
if(col==0) |
|---|
| 439 |
{ |
|---|
| 440 |
int i=((QComboTableItem*)table1->item(row,col))->currentItem(); |
|---|
| 441 |
((QComboTableItem*)table1->item(row,col+1))->setStringList(sl[i]); |
|---|
| 442 |
((QComboTableItem*)table1->item(row,col+2))->setStringList(prop[i]); |
|---|
| 443 |
} |
|---|
| 444 |
|
|---|
| 445 |
if(col==0||col == 1) |
|---|
| 446 |
{ |
|---|
| 447 |
QString tmp=((QComboTableItem*)table1->item(row,1))->text(); |
|---|
| 448 |
/* |
|---|
| 449 |
map<string,Sensor*>::iterator it=ag->sm->AllSensorList.find(tmp.latin1()); |
|---|
| 450 |
if(it!=ag->sm->AllSensorList.end()) |
|---|
| 451 |
{ |
|---|
| 452 |
textLabelComment->setText((*it).second->GetComment().c_str()); |
|---|
| 453 |
} |
|---|
| 454 |
*/ |
|---|
| 455 |
} |
|---|
| 456 |
|
|---|
| 457 |
if(col==5) showCondition(); |
|---|
| 458 |
} |
|---|
| 459 |
|
|---|
| 460 |
void AlarmPropGUI::showCondition() |
|---|
| 461 |
{ |
|---|
| 462 |
//show the general condition info |
|---|
| 463 |
map<unsigned int,QStringList> cl; |
|---|
| 464 |
for(int i=0;i<table1->numRows();i++) |
|---|
| 465 |
{ |
|---|
| 466 |
QString groupS=table1->text(i,5); |
|---|
| 467 |
if(groupS.isEmpty()) |
|---|
| 468 |
{ |
|---|
| 469 |
textLabelShowRule->setText(_("Wrong Group Number")); |
|---|
| 470 |
return; |
|---|
| 471 |
} |
|---|
| 472 |
else |
|---|
| 473 |
{ |
|---|
| 474 |
textLabelShowRule->setText(""); |
|---|
| 475 |
unsigned int group=groupS.toUInt(); |
|---|
| 476 |
if(cl.find(group)==cl.end()) |
|---|
| 477 |
cl.insert(pair<unsigned int,QStringList>(group,QStringList(table1->verticalHeader()->label(i)))); |
|---|
| 478 |
else cl.find(group)->second.append(table1->verticalHeader()->label(i)); |
|---|
| 479 |
} |
|---|
| 480 |
} |
|---|
| 481 |
QString groupRelation; |
|---|
| 482 |
QString conditionRelation; |
|---|
| 483 |
if(radioButtonAnd->isChecked()) |
|---|
| 484 |
{ |
|---|
| 485 |
groupRelation=" && "; |
|---|
| 486 |
conditionRelation=" || "; |
|---|
| 487 |
} |
|---|
| 488 |
else |
|---|
| 489 |
{ |
|---|
| 490 |
groupRelation=" || "; |
|---|
| 491 |
conditionRelation=" && "; |
|---|
| 492 |
} |
|---|
| 493 |
QString tmp; |
|---|
| 494 |
for(map<unsigned int,QStringList>::iterator it=cl.begin();it!=cl.end();) |
|---|
| 495 |
{ |
|---|
| 496 |
tmp+="( "; |
|---|
| 497 |
for(QStringList::iterator i=it->second.begin();i!=it->second.end();) |
|---|
| 498 |
{ |
|---|
| 499 |
tmp+=*i; |
|---|
| 500 |
if(++i!=it->second.end()) tmp+=conditionRelation; |
|---|
| 501 |
} |
|---|
| 502 |
tmp+=" )"; |
|---|
| 503 |
|
|---|
| 504 |
if(++it!=cl.end()) tmp+=groupRelation; |
|---|
| 505 |
} |
|---|
| 506 |
textLabelShowRule->setText(tmp); |
|---|
| 507 |
} |
|---|
| 508 |
|
|---|
| 509 |
void AlarmPropGUI::showAdvance() |
|---|
| 510 |
{ |
|---|
| 511 |
for(int i=table1->numRows();i>0;i--) |
|---|
| 512 |
{ |
|---|
| 513 |
table1->removeRow(i-1); |
|---|
| 514 |
} |
|---|
| 515 |
vector<string> * conditions=rule->FetchCondition(); |
|---|
| 516 |
for(vector<string>::iterator pos=conditions->begin();pos!=conditions->end();pos++) |
|---|
| 517 |
{ |
|---|
| 518 |
QString tmp((*pos).c_str()); |
|---|
| 519 |
newTableItem(tmp); |
|---|
| 520 |
} |
|---|
| 521 |
delete conditions; |
|---|
| 522 |
table1->setRowLabels(conditionList); |
|---|
| 523 |
switch(rule->GetConditionListType()) |
|---|
| 524 |
{ |
|---|
| 525 |
case 0: |
|---|
| 526 |
//unknown type-> rule =true |
|---|
| 527 |
break; |
|---|
| 528 |
case 1: |
|---|
| 529 |
//DNF (group || group condition &&condition ) |
|---|
| 530 |
radioButtonAnd->setChecked(false); |
|---|
| 531 |
radioButtonOr->setChecked(true); |
|---|
| 532 |
break; |
|---|
| 533 |
case 2: |
|---|
| 534 |
//CNF( group && group condition || condition) |
|---|
| 535 |
radioButtonAnd->setChecked(true); |
|---|
| 536 |
radioButtonOr->setChecked(false); |
|---|
| 537 |
break; |
|---|
| 538 |
} |
|---|
| 539 |
} |
|---|
| 540 |
|
|---|
| 541 |
void AlarmPropGUI::showSimple() |
|---|
| 542 |
{ |
|---|
| 543 |
for(SimpleCondition* sc=simpleConditionList.first();sc;sc=simpleConditionList.next()) |
|---|
| 544 |
{ |
|---|
| 545 |
this->deleteChild(sc); |
|---|
| 546 |
} |
|---|
| 547 |
for(int i=0;i<table1->numRows();i++) |
|---|
| 548 |
{ |
|---|
| 549 |
newCondition(i); |
|---|
| 550 |
} |
|---|
| 551 |
//set "or" "and" |
|---|
| 552 |
//if() |
|---|
| 553 |
switch(rule->GetConditionListType()) |
|---|
| 554 |
{ |
|---|
| 555 |
case 0: |
|---|
| 556 |
//unknown type-> rule =true |
|---|
| 557 |
break; |
|---|
| 558 |
case 1: |
|---|
| 559 |
//DNF (group || 0 condition &&condition ) |
|---|
| 560 |
radioButtonAndS->setChecked(true); |
|---|
| 561 |
radioButtonOrS->setChecked(false); |
|---|
| 562 |
break; |
|---|
| 563 |
case 2: |
|---|
| 564 |
//CNF( group && 1 condition || condition) |
|---|
| 565 |
radioButtonAndS->setChecked(false); |
|---|
| 566 |
radioButtonOrS->setChecked(true); |
|---|
| 567 |
break; |
|---|
| 568 |
} |
|---|
| 569 |
} |
|---|
| 570 |
|
|---|
| 571 |
void AlarmPropGUI::setGroupConsults() |
|---|
| 572 |
{ |
|---|
| 573 |
/* |
|---|
| 574 |
if(add) |
|---|
| 575 |
{ |
|---|
| 576 |
if(couldSimple==false) return; |
|---|
| 577 |
bool ok=false; |
|---|
| 578 |
unsigned int i=groupNum.toUInt(&ok); |
|---|
| 579 |
if(ok) |
|---|
| 580 |
{ |
|---|
| 581 |
if(groupList.count()==0) |
|---|
| 582 |
{ |
|---|
| 583 |
groupList.push_back(i); |
|---|
| 584 |
couldSimple=true; |
|---|
| 585 |
return ; |
|---|
| 586 |
} |
|---|
| 587 |
if(groupList.find(i)!=groupList.end()) couldSimple=false; |
|---|
| 588 |
else |
|---|
| 589 |
} |
|---|
| 590 |
} |
|---|
| 591 |
else |
|---|
| 592 |
{ |
|---|
| 593 |
*/ |
|---|
| 594 |
QStringList gl; |
|---|
| 595 |
bool couldSimple=true; |
|---|
| 596 |
for(int i=table1->numRows();i>0;i--) |
|---|
| 597 |
{ |
|---|
| 598 |
if(gl.count()==0) gl.push_back(table1->text(i-1,5)); |
|---|
| 599 |
if(gl.findIndex(table1->text(i-1,5))==-1) couldSimple=false; |
|---|
| 600 |
} |
|---|
| 601 |
|
|---|
| 602 |
if(couldSimple) pushButtonSimple->setEnabled(true); |
|---|
| 603 |
else pushButtonSimple->setEnabled(false); |
|---|
| 604 |
} |
|---|
| 605 |
|
|---|
| 606 |
void AlarmPropGUI::commit() |
|---|
| 607 |
{ |
|---|
| 608 |
if(this->isVisible()) |
|---|
| 609 |
{ |
|---|
| 610 |
if(this->apply()) |
|---|
| 611 |
{ |
|---|
| 612 |
this->close(); |
|---|
| 613 |
} |
|---|
| 614 |
} |
|---|
| 615 |
} |
|---|
| 616 |
|
|---|
| 617 |
bool AlarmPropGUI::apply() |
|---|
| 618 |
{ |
|---|
| 619 |
if(!request_check()) return false; |
|---|
| 620 |
|
|---|
| 621 |
conditionList.clear(); |
|---|
| 622 |
QHeader * hheader=table1->verticalHeader(); |
|---|
| 623 |
for(int i=0;i<table1->numRows();i++) |
|---|
| 624 |
{ |
|---|
| 625 |
conditionList << hheader->label(i); |
|---|
| 626 |
} |
|---|
| 627 |
|
|---|
| 628 |
//newRule=true; |
|---|
| 629 |
//rule=new PolicyRule(LIMEMONITOR_GROUPNAME); |
|---|
| 630 |
// QString groupStr(LIMEMONITOR_GROUPNAME); |
|---|
| 631 |
QString tmp=name_le->text(); |
|---|
| 632 |
QString comm = comments_le->text(); |
|---|
| 633 |
|
|---|
| 634 |
for (vector<PolicyRule*>::iterator it = ag->pm->ruleList.begin(); it!=ag->pm->ruleList.end();it++ ) |
|---|
| 635 |
{ |
|---|
| 636 |
//if(tmp==(*it)->GetName()) |
|---|
| 637 |
if(rule==*it) |
|---|
| 638 |
{ |
|---|
| 639 |
//newRule=false; |
|---|
| 640 |
//delete rule; |
|---|
| 641 |
//rule=*it; |
|---|
| 642 |
ag->pm->ruleList.erase(it); |
|---|
| 643 |
break; |
|---|
| 644 |
} |
|---|
| 645 |
} |
|---|
| 646 |
|
|---|
| 647 |
// if(tmp.left(groupStr.length())!=groupStr) tmp=LIMEMONITOR_GROUPNAME+tmp; |
|---|
| 648 |
rule->SetName(tmp.latin1(),!newRule); |
|---|
| 649 |
rule->SetComments(comm.latin1()); |
|---|
| 650 |
vector<string> * conditionName=rule->FetchConditionName(); |
|---|
| 651 |
if(widgetStack1->visibleWidget()==widgetStack1->widget(1)) |
|---|
| 652 |
{ |
|---|
| 653 |
/* |
|---|
| 654 |
//simpe |
|---|
| 655 |
if(radioButtonAndS->isChecked()) rule->SetConditionListType(1); |
|---|
| 656 |
else rule->SetConditionListType(2); |
|---|
| 657 |
//delete |
|---|
| 658 |
for(vector<string>::iterator it=conditionName->begin();it!=conditionName->end();it++) |
|---|
| 659 |
{ |
|---|
| 660 |
bool notFound=true; |
|---|
| 661 |
for(SimpleCondition * sc=simpleConditionList.first();sc;sc=simpleConditionList.next()) |
|---|
| 662 |
{ |
|---|
| 663 |
if(sc->lineEditName->text()==(*it).c_str()) |
|---|
| 664 |
{ |
|---|
| 665 |
notFound=false; |
|---|
| 666 |
break; |
|---|
| 667 |
} |
|---|
| 668 |
} |
|---|
| 669 |
if(notFound) rule->DeleteCondition((*it).c_str()); |
|---|
| 670 |
} |
|---|
| 671 |
|
|---|
| 672 |
//create or modify |
|---|
| 673 |
for(SimpleCondition * sc=simpleConditionList.first();sc;sc=simpleConditionList.next()) |
|---|
| 674 |
{ |
|---|
| 675 |
bool negitated; |
|---|
| 676 |
int type; |
|---|
| 677 |
switch(sc->when_cb->currentItem()) |
|---|
| 678 |
{ |
|---|
| 679 |
case 0: |
|---|
| 680 |
negitated=false; |
|---|
| 681 |
type=1; |
|---|
| 682 |
break; |
|---|
| 683 |
case 1: |
|---|
| 684 |
negitated=true; |
|---|
| 685 |
type=1; |
|---|
| 686 |
break; |
|---|
| 687 |
case 2: |
|---|
| 688 |
negitated=false; |
|---|
| 689 |
type=2; |
|---|
| 690 |
break; |
|---|
| 691 |
case 3: |
|---|
| 692 |
negitated=false; |
|---|
| 693 |
type=0; |
|---|
| 694 |
break; |
|---|
| 695 |
case 4: |
|---|
| 696 |
negitated=true; |
|---|
| 697 |
type=0; |
|---|
| 698 |
break; |
|---|
| 699 |
case 5: |
|---|
| 700 |
default: |
|---|
| 701 |
negitated=true; |
|---|
| 702 |
type=2; |
|---|
| 703 |
} |
|---|
| 704 |
|
|---|
| 705 |
map<string,Sensor*>::iterator it=ag->sm->AllSensorList.find((const char*)(sc->comboBoxInst->currentText().utf8())); |
|---|
| 706 |
if(it!=ag->sm->AllSensorList.end()) |
|---|
| 707 |
{ |
|---|
| 708 |
bool notFound=true; |
|---|
| 709 |
for(vector<string>::iterator spos=conditionName->begin();spos!=conditionName->end();spos++) |
|---|
| 710 |
{ |
|---|
| 711 |
if((*spos)==sc->lineEditName->text().latin1()) |
|---|
| 712 |
{ |
|---|
| 713 |
notFound=false; |
|---|
| 714 |
break; |
|---|
| 715 |
} |
|---|
| 716 |
} |
|---|
| 717 |
if(notFound) |
|---|
| 718 |
{ |
|---|
| 719 |
rule->AddCondition(sc->lineEditName->text().latin1(),(*it).second->GetCOP().c_str(), |
|---|
| 720 |
sc->comboBoxProp->currentText().latin1(),sc->lineEditValue->text().latin1(),type,0,negitated); |
|---|
| 721 |
} |
|---|
| 722 |
else |
|---|
| 723 |
{ |
|---|
| 724 |
rule->ModifyCondition(sc->lineEditName->text().latin1(),(*it).second->GetCOP().c_str(), |
|---|
| 725 |
sc->comboBoxProp->currentText().latin1(),sc->lineEditValue->text().latin1(),type,0,negitated); |
|---|
| 726 |
} |
|---|
| 727 |
} |
|---|
| 728 |
} |
|---|
| 729 |
*/ |
|---|
| 730 |
} |
|---|
| 731 |
else |
|---|
| 732 |
{ |
|---|
| 733 |
//advance |
|---|
| 734 |
if(radioButtonOr->isChecked()) rule->SetConditionListType(1); |
|---|
| 735 |
else rule->SetConditionListType(2); |
|---|
| 736 |
for(vector<string>::iterator pos=conditionName->begin();pos!=conditionName->end();) |
|---|
| 737 |
{ |
|---|
| 738 |
if(conditionList.findIndex((*pos).c_str())==-1) |
|---|
| 739 |
{ |
|---|
| 740 |
rule->DeleteCondition((*pos).c_str()); |
|---|
| 741 |
conditionName->erase(pos); |
|---|
| 742 |
continue; |
|---|
| 743 |
} |
|---|
| 744 |
pos++; |
|---|
| 745 |
} |
|---|
| 746 |
|
|---|
| 747 |
int row=0; |
|---|
| 748 |
for(QStringList::iterator it=conditionList.begin();it!=conditionList.end();it++,row++) |
|---|
| 749 |
{ |
|---|
| 750 |
QString inst=((QComboTableItem*)table1->item(row,1))->currentText(); |
|---|
| 751 |
QString prop=((QComboTableItem*)table1->item(row,2))->currentText(); |
|---|
| 752 |
int when=((QComboTableItem*)table1->item(row,3))->currentItem(); |
|---|
| 753 |
bool negitated; |
|---|
| 754 |
int type; |
|---|
| 755 |
switch(when) |
|---|
| 756 |
{ |
|---|
| 757 |
case 0: |
|---|
| 758 |
negitated=false; |
|---|
| 759 |
type=1; |
|---|
| 760 |
break; |
|---|
| 761 |
case 1: |
|---|
| 762 |
negitated=true; |
|---|
| 763 |
type=1; |
|---|
| 764 |
break; |
|---|
| 765 |
case 2: |
|---|
| 766 |
negitated=false; |
|---|
| 767 |
type=2; |
|---|
| 768 |
break; |
|---|
| 769 |
case 3: |
|---|
| 770 |
negitated=false; |
|---|
| 771 |
type=0; |
|---|
| 772 |
break; |
|---|
| 773 |
case 4: |
|---|
| 774 |
negitated=true; |
|---|
| 775 |
type=0; |
|---|
| 776 |
break; |
|---|
| 777 |
case 5: |
|---|
| 778 |
default: |
|---|
| 779 |
negitated=true; |
|---|
| 780 |
type=2; |
|---|
| 781 |
|
|---|
| 782 |
} |
|---|
| 783 |
|
|---|
| 784 |
QString value=table1->item(row,4)->text(); |
|---|
| 785 |
QString groupS=table1->item(row,5)->text(); |
|---|
| 786 |
unsigned int group=groupS.toUInt(); |
|---|
| 787 |
map<string,Sensor*>::iterator sit=ag->sm->AllSensorList.find((const char *)(inst.utf8())); |
|---|
| 788 |
if(sit!=ag->sm->AllSensorList.end()) |
|---|
| 789 |
{ |
|---|
| 790 |
bool notFound=true; |
|---|
| 791 |
for(vector<string>::iterator spos=conditionName->begin();spos!=conditionName->end();spos++) |
|---|
| 792 |
{ |
|---|
| 793 |
if((*spos)==(*it).latin1()) |
|---|
| 794 |
{ |
|---|
| 795 |
notFound=false; |
|---|
| 796 |
break; |
|---|
| 797 |
} |
|---|
| 798 |
} |
|---|
| 799 |
if(notFound) |
|---|
| 800 |
{ |
|---|
| 801 |
//create |
|---|
| 802 |
rule->AddCondition((*it).latin1(),(*sit).second->GetCOP().c_str(), |
|---|
| 803 |
(prop.latin1()),value.latin1(),type,group,negitated); |
|---|
| 804 |
} |
|---|
| 805 |
else |
|---|
| 806 |
{ |
|---|
| 807 |
//modify |
|---|
| 808 |
rule->ModifyCondition((*it).latin1(),(*sit).second->GetCOP().c_str(), |
|---|
| 809 |
(prop.latin1()),value.latin1(),type,group,negitated); |
|---|
| 810 |
} |
|---|
| 811 |
} |
|---|
| 812 |
} |
|---|
| 813 |
} |
|---|
| 814 |
|
|---|
| 815 |
//action |
|---|
| 816 |
vector<string> * actionName=rule->FetchActionName(); |
|---|
| 817 |
QStringList actionList; |
|---|
| 818 |
if(syslog_cb->isChecked()) actionList<<"syslog"; |
|---|
| 819 |
if(smtp_cb->isChecked()) actionList<<"MailTo:"+smtp_param_le->text(); |
|---|
| 820 |
if(log_cb->isChecked()) actionList<<"LogInto:"+log_param_le->text(); |
|---|
| 821 |
if(command_cb->isChecked()) actionList<<"Cmd:"+command_param_le->text(); |
|---|
| 822 |
|
|---|
| 823 |
for(vector<string>::iterator apos=actionName->begin();apos!=actionName->end();apos++) |
|---|
| 824 |
{ |
|---|
| 825 |
if(actionList.findIndex((*apos).c_str())==-1) |
|---|
| 826 |
{ |
|---|
| 827 |
rule->DeleteAction((*apos).c_str()); |
|---|
| 828 |
} |
|---|
| 829 |
} |
|---|
| 830 |
|
|---|
| 831 |
for(QStringList::iterator lpos=actionList.begin();lpos!=actionList.end();lpos++) |
|---|
| 832 |
{ |
|---|
| 833 |
bool notFound=true; |
|---|
| 834 |
for(vector<string>::iterator apos=actionName->begin();apos!=actionName->end();apos++) |
|---|
| 835 |
{ |
|---|
| 836 |
if( (*apos) == (*lpos).latin1() ) |
|---|
| 837 |
{ |
|---|
| 838 |
notFound=false; |
|---|
| 839 |
break; |
|---|
| 840 |
} |
|---|
| 841 |
} |
|---|
| 842 |
if(notFound) |
|---|
| 843 |
{ |
|---|
| 844 |
rule->AddAction((*lpos).latin1(),true); |
|---|
| 845 |
} |
|---|
| 846 |
else |
|---|
| 847 |
{ |
|---|
| 848 |
//rule->ModifyAction((*lpos).latin1(),true); |
|---|
| 849 |
} |
|---|
| 850 |
} |
|---|
| 851 |
delete actionName; |
|---|
| 852 |
int ret=0; |
|---|
| 853 |
try{ |
|---|
| 854 |
if(ag->hostItem && ag->hostItem->client) |
|---|
| 855 |
rule->CommitRuleObject(ag->hostItem->client); |
|---|
| 856 |
}CATCH_EXCEPTION(NULL,_("Failed"),_("Failed to commit the policy rule!"),ret); |
|---|
| 857 |
if(ret!=0) |
|---|
| 858 |
{ |
|---|
| 859 |
return false; |
|---|
| 860 |
} |
|---|
| 861 |
else ag->pm->addRule(rule); |
|---|
| 862 |
int status; |
|---|
| 863 |
|
|---|
| 864 |
try{ |
|---|
| 865 |
status=ag->pm->queryDaemonStatus(); |
|---|
| 866 |
if(status==-1) |
|---|
| 867 |
{ |
|---|
| 868 |
//unknow status of daemon service in provider machine |
|---|
| 869 |
} |
|---|
| 870 |
else if(status==0) |
|---|
| 871 |
{ |
|---|
| 872 |
//daemon service is not started |
|---|
| 873 |
QMessageBox a; |
|---|
| 874 |
if( 0== a.warning(this,_("Warning"),_("If you want the added alarm can be reported, you must to start the service limeperfd. Do you want to start it now?"),_("OK"),_("Cancel"))) |
|---|
| 875 |
//start it |
|---|
| 876 |
ag->pm->startDaemon(); |
|---|
| 877 |
} |
|---|
| 878 |
}CATCH_EXCEPTION(NULL,_("Failed"),_("Failed about limeperfd service"),ret); |
|---|
| 879 |
|
|---|
| 880 |
ag->refresh_alarm(); |
|---|
| 881 |
newRule=false; |
|---|
| 882 |
return true; |
|---|
| 883 |
} |
|---|
| 884 |
|
|---|
| 885 |
void AlarmPropGUI::showAction() |
|---|
| 886 |
{ |
|---|
| 887 |
vector<string> * actions=rule->FetchAction(); |
|---|
| 888 |
smtp_cb->setChecked(false); |
|---|
| 889 |
log_cb->setChecked(false); |
|---|
| 890 |
syslog_cb->setChecked(false); |
|---|
| 891 |
command_cb->setChecked(false); |
|---|
| 892 |
for(vector<string>::iterator pos=actions->begin();pos!=actions->end();pos++) |
|---|
| 893 |
{ |
|---|
| 894 |
QString tmp((*pos).c_str()); |
|---|
| 895 |
QString keyword=tmp.section("\n",0,0); |
|---|
| 896 |
QString tt=keyword.simplifyWhiteSpace().section(":",0,0).lower(); |
|---|
| 897 |
if(tt=="mailto") |
|---|
| 898 |
{ |
|---|
| 899 |
smtp_cb->setChecked(true); |
|---|
| 900 |
smtp_param_le->setText(keyword.simplifyWhiteSpace().section(":",1)); |
|---|
| 901 |
} |
|---|
| 902 |
else if(tt=="loginto") |
|---|
| 903 |
{ |
|---|
| 904 |
log_cb->setChecked(true); |
|---|
| 905 |
log_param_le->setText(keyword.simplifyWhiteSpace().section(":",1)); |
|---|
| 906 |
} |
|---|
| 907 |
else if(tt=="syslog") |
|---|
| 908 |
{ |
|---|
| 909 |
syslog_cb->setChecked(true); |
|---|
| 910 |
} |
|---|
| 911 |
else if(tt="cmd") |
|---|
| 912 |
{ |
|---|
| 913 |
command_cb->setChecked(true); |
|---|
| 914 |
command_param_le->setText(keyword.simplifyWhiteSpace().section(":",1)); |
|---|
| 915 |
} |
|---|
| 916 |
} |
|---|
| 917 |
delete actions; |
|---|
| 918 |
} |
|---|
| 919 |
|
|---|
| 920 |
bool AlarmPropGUI::request_check() |
|---|
| 921 |
{ |
|---|
| 922 |
int tabwidget= main_tab->currentPageIndex(); |
|---|
| 923 |
main_tab->setCurrentPage(0); |
|---|
| 924 |
if(name_le->text().isEmpty()) |
|---|
| 925 |
{ |
|---|
| 926 |
QMessageBox::warning(this,_("No Rule Name"),_("The rule name could not be null!\n")); |
|---|
| 927 |
name_le->setFocus(); |
|---|
| 928 |
return false; |
|---|
| 929 |
} |
|---|
| 930 |
if(widgetStack1->visibleWidget()==widgetStack1->widget(1)) |
|---|
| 931 |
{ |
|---|
| 932 |
/* |
|---|
| 933 |
for(SimpleCondition * sc=simpleConditionList.first();sc;sc=simpleConditionList.next()) |
|---|
| 934 |
{ |
|---|
| 935 |
if(sc->lineEditName->text().isEmpty()) |
|---|
| 936 |
{ |
|---|
| 937 |
QMessageBox::warning(this,_("No Condition Name"),_("The condition name could not be null!\n")); |
|---|
| 938 |
sc->lineEditName->setFocus(); |
|---|
| 939 |
return false; |
|---|
| 940 |
} |
|---|
| 941 |
|
|---|
| 942 |
if(sc->comboBoxInst->currentText().isEmpty()) |
|---|
| 943 |
{ |
|---|
| 944 |
QMessageBox::warning(this,_("No Target Instacnce"),_("There is no target instance to be monitored!\n")); |
|---|
| 945 |
sc->comboBoxInst->setFocus(); |
|---|
| 946 |
return false; |
|---|
| 947 |
} |
|---|
| 948 |
|
|---|
| 949 |
if(sc->lineEditValue->text().isEmpty()) |
|---|
| 950 |
{ |
|---|
| 951 |
QMessageBox::warning(this,_("No Tagert Value"),_("There is no target value to be checked!\n")); |
|---|
| 952 |
sc->lineEditValue->setFocus(); |
|---|
| 953 |
return false; |
|---|
| 954 |
} |
|---|
| 955 |
else |
|---|
| 956 |
{ |
|---|
| 957 |
bool ok; |
|---|
| 958 |
sc->lineEditValue->text().toDouble ( &ok) ; |
|---|
| 959 |
if(!ok) |
|---|
| 960 |
{ |
|---|
| 961 |
QMessageBox::warning(this,_("Wrong Target Value"),_("The target value must be effect value!\n")); |
|---|
| 962 |
sc->lineEditValue->setFocus(); |
|---|
| 963 |
return false; |
|---|
| 964 |
} |
|---|
| 965 |
} |
|---|
| 966 |
} |
|---|
| 967 |
*/ |
|---|
| 968 |
} |
|---|
| 969 |
else |
|---|
| 970 |
{ |
|---|
| 971 |
for(int i=0;i< table1->numRows();i++) |
|---|
| 972 |
{ |
|---|
| 973 |
table1->setCurrentCell(i,1); |
|---|
| 974 |
|
|---|
| 975 |
if(table1->item(i,1)==0||table1->item(i,1)->text().isEmpty()) |
|---|
| 976 |
{ |
|---|
| 977 |
QMessageBox::warning(this,_("No Target Instacnce"),_("There is no target instance to be monitored!\n")); |
|---|
| 978 |
table1->setCurrentCell(i,1); |
|---|
| 979 |
return false; |
|---|
| 980 |
} |
|---|
| 981 |
if(table1->item(i,4)==0||table1->item(i,4)->text().isEmpty()) |
|---|
| 982 |
{ |
|---|
| 983 |
QMessageBox::warning(this,_("No Tagert Value"),_("There is no target value to be checked!\n")); |
|---|
| 984 |
table1->setCurrentCell(i,4); |
|---|
| 985 |
return false; |
|---|
| 986 |
} |
|---|
| 987 |
if(table1->item(i,4)) |
|---|
| 988 |
{ |
|---|
| 989 |
bool ok; |
|---|
| 990 |
table1->item(i,4)->text().toDouble( &ok); |
|---|
| 991 |
if(!ok) |
|---|
| 992 |
{ |
|---|
| 993 |
QMessageBox::warning(this,_("Wrong Target Value"),_("The target value must be effect value!\n")); |
|---|
| 994 |
table1->setCurrentCell(i,4); |
|---|
| 995 |
return false; |
|---|
| 996 |
} |
|---|
| 997 |
} |
|---|
| 998 |
if(table1->item(i,5)==0||table1->item(i,5)->text().isEmpty()) |
|---|
| 999 |
{ |
|---|
| 1000 |
QMessageBox::warning(this,_("No Condition Group Number"),_("There is no condition group number\n")); |
|---|
| 1001 |
table1->setCurrentCell(i,5); |
|---|
| 1002 |
return false; |
|---|
| 1003 |
} |
|---|
| 1004 |
} |
|---|
| 1005 |
} |
|---|
| 1006 |
main_tab->setCurrentPage(1); |
|---|
| 1007 |
|
|---|
| 1008 |
if(smtp_cb->isChecked()) |
|---|
| 1009 |
{ |
|---|
| 1010 |
if(smtp_param_le->text().isEmpty()) |
|---|
| 1011 |
{ |
|---|
| 1012 |
QMessageBox::warning(this,_("No Mail Address"),_("There is no mail address!\n")); |
|---|
| 1013 |
smtp_param_le->setFocus(); |
|---|
| 1014 |
return false; |
|---|
| 1015 |
} |
|---|
| 1016 |
} |
|---|
| 1017 |
|
|---|
| 1018 |
if(log_cb->isChecked()) |
|---|
| 1019 |
{ |
|---|
| 1020 |
if(log_param_le->text().isEmpty()) |
|---|
| 1021 |
{ |
|---|
| 1022 |
QMessageBox::warning(this,_("No Log File Path"),_("There is no log file path!\n")); |
|---|
| 1023 |
log_param_le->setFocus(); |
|---|
| 1024 |
return false; |
|---|
| 1025 |
} |
|---|
| 1026 |
if(! log_param_le->text().stripWhiteSpace().startsWith("/")) |
|---|
| 1027 |
{ |
|---|
| 1028 |
QMessageBox::warning(this,_("Wrong Log File Path"),_("The log file path is not a valid path!\n")); |
|---|
| 1029 |
log_param_le->setFocus(); |
|---|
| 1030 |
return false; |
|---|
| 1031 |
} |
|---|
| 1032 |
|
|---|
| 1033 |
} |
|---|
| 1034 |
|
|---|
| 1035 |
if(command_cb->isChecked()) |
|---|
| 1036 |
{ |
|---|
| 1037 |
if(command_param_le->text().isEmpty()) |
|---|
| 1038 |
{ |
|---|
| 1039 |
QMessageBox::warning(this,_("No Cmd string"),_("There is no cmd string!\n")); |
|---|
| 1040 |
command_param_le->setFocus(); |
|---|
| 1041 |
return false; |
|---|
| 1042 |
} |
|---|
| 1043 |
} |
|---|
| 1044 |
|
|---|
| 1045 |
main_tab->setCurrentPage(tabwidget); |
|---|
| 1046 |
return true; |
|---|
| 1047 |
} |
|---|
| 1048 |
|
|---|
| 1049 |
void AlarmPropGUI::selectFile() |
|---|
| 1050 |
{ |
|---|
| 1051 |
if(ag->hostItem && ag->hostItem->client) |
|---|
| 1052 |
{ |
|---|
| 1053 |
QString exportFileName = getSaveFileName( ag->hostItem->client);//, tr("log file"), |
|---|
| 1054 |
// this,tr("Save File Dialog"),tr("Choose a file") ); |
|---|
| 1055 |
if(exportFileName == "") return; |
|---|
| 1056 |
else |
|---|
| 1057 |
{ |
|---|
| 1058 |
int pos=exportFileName.find("wbem://"); |
|---|
| 1059 |
if(pos!=-1 && exportFileName.length()>7) exportFileName=exportFileName.mid(pos+7); |
|---|
| 1060 |
log_param_le->setText(exportFileName); |
|---|
| 1061 |
} |
|---|
| 1062 |
} |
|---|
| 1063 |
} |
|---|