mstrio > users_and_groups > contact_group

class mstrio.users_and_groups.contact_group.ContactGroup(connection, id=None, name=None)

Bases: EntityBase, DeleteMixin

Object representation of Strategy One Contact Group object

Parameters:
  • connection (Connection) –

  • id (str | None) –

  • name (str | None) –

name

contact group’s name

id

contact group’s id

description

contact group’s description

enabled

specifies if a contact group is enabled

linked_user

user linked to contact group, instance of User

members

list of contact group’s members, instances of ContactGroupMember

memberships

list of Contact Groups that the Contact Group belongs to

connection

instance of Connection class, represents connection to Strategy One Intelligence Server

add_members(members)

Add member

Parameters:

members (Iterable[ContactGroupMember | Contact | ContactGroup]) – list of members to add to contact group

alter(name=None, description=None, enabled=None, linked_user=None, members=None)

Update properties of a contact group

Parameters:
  • name (str | None) – name of a contact

  • description (str | None) – description of a contact

  • enabled (bool | None) – specifies if a contact is enabled

  • linked_user (User | str | None) – an object of class User linked to the contact

  • members (Iterable[ContactGroupMember | dict] | None) – list of contact group members, instances of ContactGroupMember

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

classmethod create(connection, name, linked_user, members, description=None, enabled=True)

Create a new contact group.

Parameters:
  • connection (Connection) – Strategy One connection object returned by connection.Connection()

  • name (str) – contact group name

  • linked_user (str | User) – user linked to contact

  • members (list[dict | ContactGroupMember]) – list of members

  • description (str | None) – description of contact

  • enabled (bool) – specifies if contact should be enabled

Returns:

ContactGroup object

Return type:

ContactGroup

delete(force=False)

Delete object.

Parameters:
  • force (bool) – If True, then no additional prompt will be shown before deleting object.

  • self (Entity) –

Returns:

True on success. False otherwise.

Return type:

bool

fetch(attr=None)

Fetch the latest object’s state from the I-Server.

Note

This method can overwrite local changes made to the object.

Parameters:
  • attr (Optional[str]) – Attribute name to be fetched. If not specified

  • dictionary. (it will use all getters specified in _API_GETTERS) –

  • None. (Defaults to) –

Raises:

ValueError – If attr cannot be fetched.

Return type:

None

classmethod from_dict(source, connection, to_snake_case=True, with_missing_value=False)
Overrides Dictable.from_dict() to instantiate an object from

a dictionary without calling any additional getters.

Parameters:
  • cls (T) – Class (type) of an object that should be created.

  • source (dict[str, Any]) – a dictionary from which an object will be constructed.

  • connection (Connection) – A Strategy One Connection object.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case, default True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An object of type T.

Return type:

T

list_properties(excluded_properties=None)

Fetches all attributes from the server and converts all properties of the object to a dictionary.

Parameters:

excluded_properties (list[str], optional) – A list of object properties that should be excluded from the dict. Defaults to None.

Returns:

A dictionary which keys are object’s attribute names, and

which values are object’s attribute values.

Return type:

dict

print()

Pretty Print all properties of the object.

Return type:

None

remove_members(members)

Remove member

Parameters:

members (Iterable[ContactGroupMember | Contact | ContactGroup]) – list of members to remove from contact group

classmethod to_csv(objects, name, path=None, properties=None)

Exports MSTR objects to a csv file.

Optionally, saves only the object properties specified in the properties parameter.

Parameters:
  • objects (T | list[T]) – List of objects of the same type that

  • exported. (will be) –

  • name (str) – The name of the csv file ending with ‘.csv’

  • path (Optional[str], optional) – A path to the directory where the file will be saved. Defaults to None.

  • properties (Optional[list[str]], optional) – A list of object’s attribute names that should be included in the exported file. Defaults to None.

Raises:
  • TypeError – If objects is not of type T or list of type T

  • objects.

Return type:

None

to_dataframe()

Converts all properties of the object to a dataframe.

Returns:

A DataFrame object containing object properties.

Return type:

DataFrame

to_dict(camel_case=True)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:

camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

update_properties()

Save compatible local changes of the object attributes to the I-Server. Changes are retrieved from the self._altered_properties dictionary. After the process of update has finished, self._altered_properties is cleared. For this method to work properly, you must override the _alter_properties() method in a subclass.

Raises:

requests.HTTPError – If I-Server raises exception

Return type:

None

class mstrio.users_and_groups.contact_group.ContactGroupMember(name, type, id=None, description=None, enabled=True)

Bases: Dictable

ContactGroupMember class, representing either Contact or ContactGroup

Parameters:
  • name (str) –

  • type (str | ContactGroupMemberType) –

  • id (str | None) –

  • description (str | None) –

  • enabled (bool) –

name

member’s name

type

type of a member, instance of ContactGroupMemberType

id

id of member, optional

description

member’s description, optional

enabled

specifies if a member is enabled

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

classmethod from_contact_or_contact_group(obj)

Initialize instance of class ContactGroupMember

Parameters:
  • obj (Contact | ContactGroup) – object to used as base for initializing instance of

  • ContactGroupMember

Returns:

ContactGroupMember object

Return type:

ContactGroupMember

classmethod from_dict(source, connection=None, to_snake_case=True, with_missing_value=False)

Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of an object that should be created.

  • source (Dict[str, Any]) – A dictionary from which an object will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An object of type T.

Return type:

T

to_dict(camel_case=True)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:

camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

enum mstrio.users_and_groups.contact_group.ContactGroupMemberType(value)

Bases: AutoName

Valid values are as follows:

CONTACT = ContactGroupMemberType.CONTACT
CONTACT_GROUP = ContactGroupMemberType.CONTACT_GROUP
USER = ContactGroupMemberType.USER
mstrio.users_and_groups.contact_group.list_contact_groups(connection, to_dictionary=False, limit=None, **filters)

Get all contact groups as list of ContactGroup objects or dictionaries.

Optionally filter the contact groups by specifying filters.

Parameters:
  • connection (object) – Strategy One connection object

  • to_dictionary (bool) – If True returns a list of contact group dicts, otherwise returns a list of contact group objects

  • limit (int | None) – limit the number of elements returned. If None (default), all objects are returned.

  • **filters – Available filter parameters: [‘id’, ‘name’, ‘description’, ‘enabled’, ‘linked_user’]

Return type:

list[’ContactGroup’] | list[dict]