]> granicus.if.org Git - icinga2/blob - lib/icinga/objectutils.cpp
Service: be handled while host is down
[icinga2] / lib / icinga / objectutils.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "icinga/objectutils.hpp"
4 #include "icinga/host.hpp"
5 #include "icinga/user.hpp"
6 #include "icinga/checkcommand.hpp"
7 #include "icinga/eventcommand.hpp"
8 #include "icinga/notificationcommand.hpp"
9 #include "icinga/hostgroup.hpp"
10 #include "icinga/servicegroup.hpp"
11 #include "icinga/usergroup.hpp"
12
13 using namespace icinga;
14
15 REGISTER_FUNCTION(Icinga, get_host, &Host::GetByName, "name");
16 REGISTER_FUNCTION(Icinga, get_service, &ObjectUtils::GetService, "host:name");
17 REGISTER_FUNCTION(Icinga, get_services, &ObjectUtils::GetServices, "host");
18 REGISTER_FUNCTION(Icinga, get_user, &User::GetByName, "name");
19 REGISTER_FUNCTION(Icinga, get_check_command, &CheckCommand::GetByName, "name");
20 REGISTER_FUNCTION(Icinga, get_event_command, &EventCommand::GetByName, "name");
21 REGISTER_FUNCTION(Icinga, get_notification_command, &NotificationCommand::GetByName, "name");
22 REGISTER_FUNCTION(Icinga, get_host_group, &HostGroup::GetByName, "name");
23 REGISTER_FUNCTION(Icinga, get_service_group, &ServiceGroup::GetByName, "name");
24 REGISTER_FUNCTION(Icinga, get_user_group, &UserGroup::GetByName, "name");
25 REGISTER_FUNCTION(Icinga, get_time_period, &TimePeriod::GetByName, "name");
26
27 Service::Ptr ObjectUtils::GetService(const Value& host, const String& name)
28 {
29         Host::Ptr hostObj;
30
31         if (host.IsObjectType<Host>())
32                 hostObj = host;
33         else
34                 hostObj = Host::GetByName(host);
35
36         if (!hostObj)
37                 return nullptr;
38
39         return hostObj->GetServiceByShortName(name);
40 }
41
42 Array::Ptr ObjectUtils::GetServices(const Value& host)
43 {
44         Host::Ptr hostObj;
45
46         if (host.IsObjectType<Host>())
47                 hostObj = host;
48         else
49                 hostObj = Host::GetByName(host);
50
51         if (!hostObj)
52                 return nullptr;
53
54         return Array::FromVector(hostObj->GetServices());
55 }