| 1133 | } |
| 1134 | |
| 1135 | void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector<String>& arguments) |
| 1136 | { |
| 1137 | Host::Ptr host = Host::GetByName(arguments[0]); |
| 1138 | |
| 1139 | if (!host) |
| 1140 | BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host services downtime for non-existent host '" + arguments[0] + "'")); |
| 1141 | |
| 1142 | String serviceName; |
| 1143 | if (arguments.size() >= 2) |
| 1144 | serviceName = arguments[1]; |
| 1145 | |
| 1146 | String startTime; |
| 1147 | if (arguments.size() >= 3) |
| 1148 | startTime = arguments[2]; |
| 1149 | |
| 1150 | String commentString; |
| 1151 | if (arguments.size() >= 4) |
| 1152 | commentString = arguments[3]; |
| 1153 | |
| 1154 | if (arguments.size() > 5) |
| 1155 | Log(LogWarning, "ExternalCommandProcessor") |
| 1156 | << ("Ignoring additional parameters for host '" + arguments[0] + "' downtime deletion."); |
| 1157 | |
| 1158 | for (const Downtime::Ptr& downtime : host->GetDowntimes()) { |
| 1159 | try { |
| 1160 | String downtimeName = downtime->GetName(); |
| 1161 | Downtime::RemoveDowntime(downtimeName, false, DowntimeRemovedByUser); |
| 1162 | |
| 1163 | Log(LogNotice, "ExternalCommandProcessor") |
| 1164 | << "Removed downtime '" << downtimeName << "'."; |
| 1165 | } catch (const invalid_downtime_removal_error& error) { |
| 1166 | Log(LogWarning, "ExternalCommandProcessor") << error.what(); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | for (const Service::Ptr& service : host->GetServices()) { |
| 1171 | if (!serviceName.IsEmpty() && serviceName != service->GetName()) |
| 1172 | continue; |
| 1173 | |
| 1174 | for (const Downtime::Ptr& downtime : service->GetDowntimes()) { |
| 1175 | if (!startTime.IsEmpty() && downtime->GetStartTime() != Convert::ToDouble(startTime)) |
| 1176 | continue; |
| 1177 | |
| 1178 | if (!commentString.IsEmpty() && downtime->GetComment() != commentString) |
| 1179 | continue; |
| 1180 | |
| 1181 | try { |
| 1182 | String downtimeName = downtime->GetName(); |
| 1183 | Downtime::RemoveDowntime(downtimeName, false, DowntimeRemovedByUser); |
| 1184 | |
| 1185 | Log(LogNotice, "ExternalCommandProcessor") |
| 1186 | << "Removed downtime '" << downtimeName << "'."; |
| 1187 | } catch (const invalid_downtime_removal_error& error) { |
| 1188 | Log(LogWarning, "ExternalCommandProcessor") << error.what(); |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | } |
nothing calls this directly
no test coverage detected