Revert "Add statusmap_image and coords host attributes."

This reverts commit 252980a6bd.

Refs #6044
This commit is contained in:
Michael Friedrich 2014-04-22 12:09:24 +02:00
parent e489c98e6d
commit fe1a83ff34
10 changed files with 82 additions and 52 deletions

View File

@ -235,17 +235,11 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
String action_url = host->GetActionUrl(); String action_url = host->GetActionUrl();
String icon_image = host->GetIconImage(); String icon_image = host->GetIconImage();
String icon_image_alt = host->GetIconImageAlt(); String icon_image_alt = host->GetIconImageAlt();
String statusmap_image = host->GetStatusmapImage(); String statusmap_image = CompatUtility::GetCustomAttributeConfig(host, "statusmap_image");
String display_name = host->GetDisplayName(); String display_name = host->GetDisplayName();
String address = host->GetAddress(); String address = host->GetAddress();
String address6 = host->GetAddress6(); String address6 = host->GetAddress6();
double x_2d, y_2d;
CompatUtility::GetHost2dCoordX(host, &x_2d);
CompatUtility::GetHost2dCoordY(host, &y_2d);
String coords = Convert::ToString(x_2d) + "," + Convert::ToString(y_2d);
fp << "define host {" "\n" fp << "define host {" "\n"
"\t" "host_name" "\t" << host->GetName() << "\n"; "\t" "host_name" "\t" << host->GetName() << "\n";
if (!display_name.IsEmpty()) { if (!display_name.IsEmpty()) {
@ -268,8 +262,6 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
fp << "\t" "icon_image_alt" "\t" << icon_image_alt << "\n"; fp << "\t" "icon_image_alt" "\t" << icon_image_alt << "\n";
if (!statusmap_image.IsEmpty()) if (!statusmap_image.IsEmpty())
fp << "\t" "statusmap_image" "\t" << statusmap_image << "\n"; fp << "\t" "statusmap_image" "\t" << statusmap_image << "\n";
if (!coords.IsEmpty())
fp << "\t" "2d_coords" "\t" << coords << "\n";
std::set<Checkable::Ptr> parents = host->GetParents(); std::set<Checkable::Ptr> parents = host->GetParents();

View File

@ -821,11 +821,7 @@ Value HostsTable::X2dAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
double coord; return CompatUtility::GetHost2dCoordX(host);
if (!CompatUtility::GetHost2dCoordX(host, &coord))
return Empty;
return coord;
} }
Value HostsTable::Y2dAccessor(const Value& row) Value HostsTable::Y2dAccessor(const Value& row)
@ -835,11 +831,7 @@ Value HostsTable::Y2dAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
double coord; return CompatUtility::GetHost2dCoordY(host);
if (!CompatUtility::GetHost2dCoordY(host, &coord))
return Empty;
return coord;
} }
Value HostsTable::LatencyAccessor(const Value& row) Value HostsTable::LatencyAccessor(const Value& row)

View File

@ -45,15 +45,17 @@ Attributes:
notes_url |**Optional.** Url for notes for the host (for example, in notification commands). notes_url |**Optional.** Url for notes for the host (for example, in notification commands).
action_url |**Optional.** Url for actions for the host (for example, an external graphing tool). action_url |**Optional.** Url for actions for the host (for example, an external graphing tool).
icon_image |**Optional.** Icon image for the host. Required for external interfaces only. icon_image |**Optional.** Icon image for the host. Required for external interfaces only.
icon_image_alt |**Optional.** Icon image description for the host. Required for external interfaces only. icon_image_alt |**Optional.** Icon image description for the host. Required for external interface only.
statusmap_image |**Optional.** Statusmap image for the host. Required for external interfaces only.
coords |**Optional.** A dictionary containing the keys `x_2d` and `y_2d` as floating point values. Required for external interfaces and status maps.
> **Best Practice** > **Best Practice**
> >
> The `address` and `address6` attributes are required for running commands using > The `address` and `address6` attributes are required for running commands using
> the `$address$` and `$address6` runtime macros. > the `$address$` and `$address6` runtime macros.
Unlike Icinga 1.x the `statusmap_image` and `2d_coords` attributes are
custom attributes only in Icinga 2.
### <a id="objecttype-hostgroup"></a> HostGroup ### <a id="objecttype-hostgroup"></a> HostGroup
A group of hosts. A group of hosts.

View File

@ -168,6 +168,18 @@ Icinga 2 allows you to define custom attributes in the `vars` dictionary.
The `notes`, `notes_url`, `action_url`, `icon_image`, `icon_image_alt` The `notes`, `notes_url`, `action_url`, `icon_image`, `icon_image_alt`
attributes for host and service objects are still available in Icinga 2. attributes for host and service objects are still available in Icinga 2.
### <a id="differences-1x-2-action-url-notes-url-notes"></a> Statusmap Image, 2D Coords
These attributes can be set using the `vars` dictionary in Icinga 2 `Host`
or `Service` objects:
vars = {
"2d_coords" = "1,2"
statusmap_image = "../../images/logos/icinga.gif"
}
External interfaces will recognize and display these attributes accordingly.
### <a id="differences-1x-2-custom-variables"></a> Custom Variables ### <a id="differences-1x-2-custom-variables"></a> Custom Variables
Icinga 1.x custom variable attributes must be prefixed using an underscore (`_`). Icinga 1.x custom variable attributes must be prefixed using an underscore (`_`).
@ -178,6 +190,8 @@ In Icinga 2 these attributes must be added to the `vars` dictionary as custom at
CV = "my custom cmdb description" CV = "my custom cmdb description"
} }
TODO
## <a id="differences-1x-2-host-service-relation"></a> Host Service Relation ## <a id="differences-1x-2-host-service-relation"></a> Host Service Relation
In Icinga 1.x a service object is associated with a host by defining the In Icinga 1.x a service object is associated with a host by defining the
@ -518,6 +532,8 @@ object for the escalation itself.
### <a id="differences-1x-2-notification-options"></a> Notification Options ### <a id="differences-1x-2-notification-options"></a> Notification Options
TODO
Unlike Icinga 1.x with the 'notification_options' attribute with comma-separated Unlike Icinga 1.x with the 'notification_options' attribute with comma-separated
state and type filters, Icinga 2 uses two configuration attributes for that. state and type filters, Icinga 2 uses two configuration attributes for that.
All state and type filter use long names or'd with a pipe together All state and type filter use long names or'd with a pipe together

View File

@ -102,15 +102,16 @@ Dictionary::Ptr HostDbObject::GetConfigFields(void) const
fields->Set("action_url", host->GetActionUrl()); fields->Set("action_url", host->GetActionUrl());
fields->Set("icon_image", host->GetIconImage()); fields->Set("icon_image", host->GetIconImage());
fields->Set("icon_image_alt", host->GetIconImageAlt()); fields->Set("icon_image_alt", host->GetIconImageAlt());
fields->Set("statusmap_image", host->GetStatusmapImage()); fields->Set("statusmap_image", CompatUtility::GetCustomAttributeConfig(host, "statusmap_image"));
double x_2d, y_2d; Host2dCoords coords = CompatUtility::GetHost2dCoords(host);
if (CompatUtility::GetHost2dCoordX(host, &x_2d) && CompatUtility::GetHost2dCoordY(host, &y_2d)) {
fields->Set("have_2d_coords", 1); fields->Set("have_2d_coords", coords.have_2d_coords);
fields->Set("x_2d", x_2d);
fields->Set("y_2d", y_2d); if (coords.have_2d_coords) {
} else fields->Set("x_2d", coords.x_2d);
fields->Set("have_2d_coords", 0); fields->Set("y_2d", coords.y_2d);
}
/* deprecated in 1.x */ /* deprecated in 1.x */
fields->Set("have_3d_coords", 0); fields->Set("have_3d_coords", 0);

View File

@ -70,28 +70,52 @@ String CompatUtility::GetHostAlias(const Host::Ptr& host)
return host->GetDisplayName(); return host->GetDisplayName();
} }
bool CompatUtility::GetHost2dCoordX(const Host::Ptr& host, double *coord) Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host)
{ {
Dictionary::Ptr coords = host->GetCoords(); ASSERT(host->OwnsLock());
if (!coords) Dictionary::Ptr vars = host->GetVars();
return false; Host2dCoords bag;
*coord = coords->Get("x_2d"); if (vars) {
String coords = vars->Get("2d_coords");
bag.have_2d_coords = (!coords.IsEmpty() ? 1 : 0);
return true; std::vector<String> tokens;
boost::algorithm::split(tokens, coords, boost::is_any_of(","));
if (tokens.size() != 2)
bag.have_2d_coords = 0;
if (bag.have_2d_coords == 1) {
bag.x_2d = tokens[0];
bag.y_2d = tokens[1];
}
} else {
bag.have_2d_coords = 0;
}
return bag;
} }
bool CompatUtility::GetHost2dCoordY(const Host::Ptr& host, double *coord) String CompatUtility::GetHost2dCoordX(const Host::Ptr& host)
{ {
Dictionary::Ptr coords = host->GetCoords(); Host2dCoords bag = GetHost2dCoords(host);
if (!coords) if (bag.have_2d_coords == 0)
return false; return Empty;
*coord = coords->Get("y_2d"); return bag.x_2d;
}
return true; String CompatUtility::GetHost2dCoordY(const Host::Ptr& host)
{
Host2dCoords bag = GetHost2dCoords(host);
if (bag.have_2d_coords == 0)
return Empty;
return bag.y_2d;
} }
int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host)

View File

@ -31,6 +31,15 @@
namespace icinga namespace icinga
{ {
/**
* @ingroup icinga
*/
struct Host2dCoords {
int have_2d_coords;
String x_2d;
String y_2d;
};
/** /**
* Compatibility utility functions. * Compatibility utility functions.
* *
@ -42,8 +51,9 @@ public:
/* host */ /* host */
static String GetHostAlias(const Host::Ptr& host); static String GetHostAlias(const Host::Ptr& host);
static bool GetHost2dCoordX(const Host::Ptr& host, double *coord); static Host2dCoords GetHost2dCoords(const Host::Ptr& host);
static bool GetHost2dCoordY(const Host::Ptr& host, double *coord); static String GetHost2dCoordX(const Host::Ptr& host);
static String GetHost2dCoordY(const Host::Ptr& host);
static int GetHostNotifyOnDown(const Host::Ptr& host); static int GetHostNotifyOnDown(const Host::Ptr& host);
static int GetHostNotifyOnUnreachable(const Host::Ptr& host); static int GetHostNotifyOnUnreachable(const Host::Ptr& host);

View File

@ -18,8 +18,6 @@ class Host : Checkable
[config] String address; [config] String address;
[config] String address6; [config] String address6;
[config] String statusmap_image;
[config] Dictionary::Ptr coords;
}; };
} }

View File

@ -68,11 +68,6 @@
%attribute %string "address", %attribute %string "address",
%attribute %string "address6", %attribute %string "address6",
%attribute %string "statusmap_image",
%attribute %dictionary "coords" {
%attribute %number "x_2d",
%attribute %number "y_2d"
}
} }
%type HostGroup { %type HostGroup {

View File

@ -1,4 +1,4 @@
GET hosts GET hosts
Columns: name notes notes_url action_url icon_image icon_image_alt statusmap_image x_2d y_2d Columns: name notes notes_url action_url icon_image icon_image_alt
ResponseHeader: fixed16 ResponseHeader: fixed16