generic object functions. More...
Public Member Functions | |
__construct ($id=false) | |
constructor | |
get_object_by_name ($name) | |
returns an object as identified by its nagios-name | |
get_default_object () | |
Obtains the default settings for new object of the type we're currently manipulating. | |
get_properties () | |
Fetches the properties for the current object type. | |
propagate_variables ($prop_vars, $obj_list, $prop_format='replace') | |
Propagates one or more variables to one or more objects. | |
get_object_name () | |
Returns the name of the object in question. | |
copy_object () | |
Create a copy of an object. | |
clone_object () | |
Create a clone of an object. | |
object_exists ($obj_type, $id) | |
Check if an object of the specified type and id exists. | |
validate_object_identifier ($value) | |
Validates an object identifier (host_name, timeperiod_name, . | |
validate_free_form_string ($value) | |
Validates a free form string. | |
validation_error ($what, $why) | |
Always returns false for convenience, as it allows expressions like this: return validation_error('everything', 'totally bogus stuff');. | |
validation_error_count () | |
returns the number of validation errors | |
validate_object () | |
Validates an object prior to saving it to database. | |
validate_custom_var ($k, $v) | |
Rudimentary validation of a custom variable. | |
find_dependant_object_types () | |
Finds all objects that can use this object type. | |
find_referenced_object_types () | |
Locate and return all object *types* referenced by the object type we're currently manipulating. | |
get_fellow_slaves () | |
Get a list of objects attached to the same master. | |
set_object_id ($id) | |
Sets the id of the current object. | |
set_master_object_id ($id) | |
Sets the master object id of the current object. | |
get_object () | |
Loads an object from database and populates $this->obj with it. | |
save_object ($user=true) | |
Writes the $this->obj to the database if it validates properly. | |
rename_object_handler () | |
Handle extra actions needed when renaming objects. | |
normalize ($obj=false, $abort_on_error=true) | |
Takes the any given object (or the current one) and normalizes it. | |
denormalize ($obj=false) | |
Takes the any given object (or the current one) and makes it denormalized. | |
filter_objs_for_changelog (&$pre, &$post) | |
Given two data objects, remove reduntant information, making the objects suitable for being included in a changelog entry. | |
update_changelog ($action=false) | |
Update the changelog with a list of changes. | |
find_slave_objects ($type=false) | |
Finds objects that cannot exist without this object. | |
find_child_objects ($obj_id=false, $obj_type=false) | |
Finds all objects with a variable that uses this object. | |
prepare_draw () | |
Prepare an object for drawing it. | |
compute_master_obj_id () | |
Attempt to calculate the id of the master object based on values found in the $this->obj array. | |
debug_print () | |
Prints debug information about the object instance. | |
template_collapse_object () | |
Removes all template derived variables from an object. | |
template_expand_object () | |
Expand an object with values from the template. | |
collapse_object ($template_collapse=true) | |
Collapses an object, removing variables that are identical to the nagios defaults and, optionally, to those set in the template. | |
expand_object ($template_expand=true) | |
Loads $this->obj with all variables possible to set for this object type. | |
delete_object () | |
Delete object after validating that it is safe to do so. | |
banish_object ($user=true) | |
The 'real' delete function. | |
get_deletion_message () | |
After deleting an object, calling this method will return an HTML formated representation of the changes made. | |
get_reasons_to_not_delete (&$all, &$hard) | |
Object deletion is sometimes dangerous or weird - this finds those cases. | |
getNagiosUserConfig () | |
Fetch nagios configuration values for user-macros ($USER1$, $USER2$ and $USER3$, . | |
getObjectById ($id=0, $type=false) | |
Fetch object record from db. | |
add_to_object_index_table () | |
Adds $this object to the object index table, meaning other objects can find it when trying to look it up, even though it may not be saved to the database yet. | |
get_sub_object_ids ($sub_obj_type, $master_link_var) | |
Fetches ids of objects dependent on the current object for their existence. | |
can_user_delete ($obj_type) | |
Determine if a user is authorized to delete a specified object. | |
filter_relations () | |
Users might not have the necessary rights to see all target objects in relations. | |
get_objects_for_user ($obj_type=false) | |
Thin wrapper for returning user's objects of an optionally specified type. | |
get_cmd_bar_links () | |
Returns a list of actions that are legal for this object type. | |
guess_master_object_type () | |
Guess the type of the master object, if applicable, and set it. | |
set_master_object_type ($type) | |
Set the type of the master object for multi-parented slave objects. | |
Static Public Member Functions | |
static | can_user_read ($obj_type, $id, $try_linked_objects=false) |
Determine if a user is authorized to read from a specified object. | |
static | can_user_write ($obj_type, $id, $try_linked_objects=false) |
Determine if a user is authorized to write to a specified object. | |
Data Fields | |
$id = false | |
The id of the current object. | |
$is_template = false | |
True if this object is a template, false otherwise. | |
$obj = false | |
The object data in a key => value array, could be regarded as $values. | |
$topic = false | |
Presentation name for this object. | |
$properties = false | |
This object's properties (required vars, allowed values etc). | |
$master_obj_id = false | |
The master object id. | |
$master_obj_type = false | |
Type of the master object. | |
$master_obj_candidates = false | |
If there are several possible master object types for this object, list them here. | |
$master_obj_identifier = false | |
Name of variable that holds the master object id. | |
$type = false | |
The type name of this object - must be overridden. | |
$db_table = false | |
Database table to use for this object. | |
$custom_vars = false | |
Custom variables present in this object. | |
$nagios_defaults = array() | |
Variables Nagios assume as default if not present in the object. | |
$slave_types = false | |
A list of object types that might depend on this object type, or false. | |
$validation_error_list = array() | |
If empty, consider validation as a) not run; or b) validated and safe. | |
$delete_message = false | |
Message when deleting or banishing objects. |
generic object functions.
Often replaced by object-specific versions with the same name.
This class is intended to be the one all the object-specific classes extend, and as such it will hold generic functions for pretty much everything.
object_class::add_to_object_index_table | ( | ) |
Adds $this object to the object index table, meaning other objects can find it when trying to look it up, even though it may not be saved to the database yet.
This is primarily used when importing a multitude of objects that have complex interdependencies. Use sparingly and at your own risk.
object_class::banish_object | ( | $ | user = true |
) |
The 'real' delete function.
$user | true if this was a user-initiated delete. Set to false when doing things that shouldn't show up in the changelog, such as undoes. |
Error or success messages can be retrieved from get_deletion_message()
Reimplemented in contact_class, user_class, and usergroup_class.
object_class::clone_object | ( | ) |
Create a clone of an object.
A clone can be saved straight away. Generally useful for slave objects. See $this->copy_object()
object_class::collapse_object | ( | $ | template_collapse = true |
) |
Collapses an object, removing variables that are identical to the nagios defaults and, optionally, to those set in the template.
$template_collapse | Also remove templated options |
object_class::compute_master_obj_id | ( | ) |
Attempt to calculate the id of the master object based on values found in the $this->obj array.
Reimplemented in hostdependency_class, and servicedependency_class.
object_class::copy_object | ( | ) |
Create a copy of an object.
A copy is like a clone, except it has no identifying name, so it needs to be modified before being saved Generally useful for master objects.
object_class::debug_print | ( | ) |
Prints debug information about the object instance.
This should never be used in production.
object_class::delete_object | ( | ) |
Delete object after validating that it is safe to do so.
.. Delete exactly one object of the type $obj_type match topic value against topic to work around pressing 'reload'
This method is adapted from previous version to use object variables and NOT to print anything - only return true or array with messages to the user to be handled by the gui.
This method calls banish_object() to do the actual deletion (mostly). Call banish_object() straight away if you want to force the deletion.
Error or success messages can be retrieved from get_deletion_message()
Reimplemented in pnp_page_class, user_class, and usergroup_class.
object_class::denormalize | ( | $ | obj = false |
) |
Takes the any given object (or the current one) and makes it denormalized.
That is, objects are normally stored in 3rd normal form (with id values instead of actual names to other objects). This function takes a normalized object and returns a denormalized one with all ids expanded to their proper names.
NacomaRelationException |
Reimplemented in service_class, and user_class.
object_class::expand_object | ( | $ | template_expand = true |
) |
Loads $this->obj with all variables possible to set for this object type.
Variables that are set in the template used by this object get the value from the template if $template_expand is true (default)
$template_expand | bool: Use variables from template |
object_class::filter_relations | ( | ) |
Users might not have the necessary rights to see all target objects in relations.
This function cleans up the object array so that any such references are removed.
object_class::find_referenced_object_types | ( | ) |
Locate and return all object *types* referenced by the object type we're currently manipulating.
object_class::find_slave_objects | ( | $ | type = false |
) |
Finds objects that cannot exist without this object.
If $type is set, returns a list of slave objects of that type. If $type isn't set, returns a map of slave types to lists of slave objects.
object_class::get_fellow_slaves | ( | ) |
Get a list of objects attached to the same master.
Reimplemented in service_class.
object_class::get_object | ( | ) |
Loads an object from database and populates $this->obj with it.
Reimplemented in extinfo_class.
object_class::get_reasons_to_not_delete | ( | &$ | all, | |
&$ | hard | |||
) |
Object deletion is sometimes dangerous or weird - this finds those cases.
We separate between "hard" and "soft" reasons. A user must be allowed to override soft reasons. A user must not be allowed to override hard reasons.
Hard reasons: If an object is used in a profile, it can't be deleted or we get SQL errors. If an object is a template that's in use, we arbitrarily decide it shouldn't be deleted. If a template object uses this object, we arbitrarily decide it shouldn't be deleted.
Soft reasons: If an object is referenced by another object, we should point that out to the user.
This logic is split out of delete_object.
$all | reference Will contain a list of reasons not to delete, "soft" or "hard". | |
$hard | reference Will contain a list of reasons not to delete, "hard" only. |
object_class::get_sub_object_ids | ( | $ | sub_obj_type, | |
$ | master_link_var | |||
) |
Fetches ids of objects dependent on the current object for their existence.
$sub_obj_type | string; Sub-object type we're interested in (ie, 'hostdependency', 'service' etc for host objects). | |
$master_link_var | string; Database field linking subobject back to current object. Eg: 'host_name' from service to host. |
object_class::getNagiosUserConfig | ( | ) |
Fetch nagios configuration values for user-macros ($USER1$, $USER2$ and $USER3$, .
..)
object_class::getObjectById | ( | $ | id = 0 , |
|
$ | type = false | |||
) |
Fetch object record from db.
object_class::normalize | ( | $ | obj = false , |
|
$ | abort_on_error = true | |||
) |
Takes the any given object (or the current one) and normalizes it.
That is, objects which have textual representations of objects they link to get those textual representations replaced with the linked-to objects' database id numbers in this method. The result replaces the current object.
This method will not remove the old state. If you want that, call self::get_default_object first.
$obj | the object state to normalize, in case it's not $this->obj | |
$abort_on_error | If false, drop invalid variables silently. |
NacomaRelationException |
Reimplemented in timeperiod_class, and user_class.
object_class::object_exists | ( | $ | obj_type, | |
$ | id | |||
) |
Check if an object of the specified type and id exists.
Objects 'exist' if they're mentioned in the Object_Index_Table for their class. This can mean that they exist in limbo if the programmer added it via the 'add_to_object_index_table()' function, but we need to live with that.
$obj_type | string; Object type to check for | |
$id | integer; Id of the object to find |
Reimplemented in user_class, and usergroup_class.
object_class::prepare_draw | ( | ) |
Prepare an object for drawing it.
This is the place to put code generic to ALL objects. For the special cases, each object can also have their own function, but this one should always be called
Reimplemented in command_class, contact_template_class, host_template_class, hostdependency_class, hostextinfo_class, service_template_class, servicedependency_class, serviceescalation_class, serviceextinfo_class, and timeperiod_class.
object_class::propagate_variables | ( | $ | prop_vars, | |
$ | obj_list, | |||
$ | prop_format = 'replace' | |||
) |
Propagates one or more variables to one or more objects.
$prop_vars | The variables to propagate (k => v array) | |
$obj_list | Array of object-id's to propagate to | |
$prop_format | The type of value propagation to use for mselect variables |
object_class::rename_object_handler | ( | ) |
Handle extra actions needed when renaming objects.
object_class::save_object | ( | $ | user = true |
) |
Writes the $this->obj to the database if it validates properly.
$user | false if this change isn't made by a user. If not, no validation will be performed, and the change won't show up in the changelog. |
Reimplemented in contact_class, host_class, pnp_page_class, service_class, user_class, and usergroup_class.
object_class::set_master_object_id | ( | $ | id | ) |
Sets the master object id of the current object.
Reimplemented in extinfo_class.
object_class::template_expand_object | ( | ) |
Expand an object with values from the template.
This is used from the validation function, which needs to see *all* values in the object as Nagios sees them.
object_class::update_changelog | ( | $ | action = false |
) |
Update the changelog with a list of changes.
Saved to db in serialized format.
$action | string; Set to 'delete' if that's what you're doing |
object_class::validate_custom_var | ( | $ | k, | |
$ | v | |||
) |
Rudimentary validation of a custom variable.
$k | variable key or name | |
$v | variable value |
object_class::validate_free_form_string | ( | $ | value | ) |
Validates a free form string.
object_class::validate_object | ( | ) |
Validates an object prior to saving it to database.
This function ensures that the object being validated:
Reimplemented in contact_class, extinfo_class, host_class, hostdependency_class, service_class, servicedependency_class, timeperiod_class, user_class, and usergroup_class.
object_class::validate_object_identifier | ( | $ | value | ) |
Validates an object identifier (host_name, timeperiod_name, .
..) for the most common cases. Note that not all objects have clearly defined identifiers.
Reimplemented in FILE_class.