예제 #1
0
    def to_list(self, lst, defvalue='-'):
        """Formats a list of strings with Host informations

        It works like :meth:`to_str` except that the input is a list of strings : This useful when
        a text has been splitted into lines.

        Args:

            str (str): A format string
            defvalue (str): String to display when a data is not available

        Returns:

            list : The list with formatted string

        Examples:

            >>> os.environ['NAGIOS_HOSTNAME']='host_to_be_monitored'
            >>> os.environ['NAGIOS_HOSTADDRESS']='192.168.0.33'
            >>> plugin = ActivePlugin()
            >>> host = Host(plugin)
            >>> host.load_data()
            >>> lst = ['{name} as got IP={ip} and custom data "{my_custom_data}"',
            ... 'Not available data are replaced by a dash: {other_data}']
            >>> print host.to_list(lst)  # doctest: +NORMALIZE_WHITESPACE
            [u'host_to_be_monitored as got IP=192.168.0.33 and custom data "last check time"',
            'Not available data are replaced by a dash: -']

            .. note::

                As you noticed, ``NAGIOS_HOSTNAME`` environment variable is stored as ``name`` in
                Host object and ``NAGIOS_HOSTADDRESS`` as ``ip``.
                ``my_custom_data`` is a persistent data that has been
                automatically loaded because set into a previous example.
        """
        return [dformat(l, self) for l in lst]
예제 #2
0
    def to_list(self, lst, defvalue='-'):
        """Formats a list of strings with Host informations

        It works like :meth:`to_str` except that the input is a list of strings : This useful when
        a text has been splitted into lines.

        Args:

            str (str): A format string
            defvalue (str): String to display when a data is not available

        Returns:

            list : The list with formatted string

        Examples:

            >>> os.environ['NAGIOS_HOSTNAME']='host_to_be_monitored'
            >>> os.environ['NAGIOS_HOSTADDRESS']='192.168.0.33'
            >>> plugin = ActivePlugin()
            >>> host = Host(plugin)
            >>> host.load_data()
            >>> lst = ['{name} as got IP={ip} and custom data "{my_custom_data}"',
            ... 'Not available data are replaced by a dash: {other_data}']
            >>> print host.to_list(lst)  # doctest: +NORMALIZE_WHITESPACE
            [u'host_to_be_monitored as got IP=192.168.0.33 and custom data "last check time"',
            'Not available data are replaced by a dash: -']

            .. note::

                As you noticed, ``NAGIOS_HOSTNAME`` environment variable is stored as ``name`` in
                Host object and ``NAGIOS_HOSTADDRESS`` as ``ip``.
                ``my_custom_data`` is a persistent data that has been
                automatically loaded because set into a previous example.
        """
        return [ dformat(l,self) for l in lst ]
예제 #3
0
    def to_str(self, str, defvalue='-'):
        """Formats a string with Host informations

        Not available data are replaced by a dash

        Args:

            str (str): A format string
            defvalue (str): String to display when a data is not available

        Returns:

            str : the formatted string

        Examples:

            >>> os.environ['NAGIOS_HOSTNAME']='host_to_be_monitored'
            >>> os.environ['NAGIOS_HOSTADDRESS']='192.168.0.33'
            >>> plugin = ActivePlugin()
            >>> host = Host(plugin)
            >>> host.load_data()
            >>> print host.to_str('{name} as got IP={ip} and custom data "{my_custom_data}"')
            host_to_be_monitored as got IP=192.168.0.33 and custom data "last check time"
            >>> print host.to_str('Not available data are replaced by a dash: {other_data}')
            Not available data are replaced by a dash: -
            >>> print host.to_str('Or by whatever you want: {other_data}','N/A')
            Or by whatever you want: N/A

            .. note::

                As you noticed, ``NAGIOS_HOSTNAME`` environment variable is stored as ``name`` in
                Host object and ``NAGIOS_HOSTADDRESS`` as ``ip``.
                ``my_custom_data`` is a persistent data that has been
                automatically loaded because set into a previous example.
        """
        return dformat(str, self, defvalue)
예제 #4
0
    def to_str(self, str, defvalue='-'):
        """Formats a string with Host informations

        Not available data are replaced by a dash

        Args:

            str (str): A format string
            defvalue (str): String to display when a data is not available

        Returns:

            str : the formatted string

        Examples:

            >>> os.environ['NAGIOS_HOSTNAME']='host_to_be_monitored'
            >>> os.environ['NAGIOS_HOSTADDRESS']='192.168.0.33'
            >>> plugin = ActivePlugin()
            >>> host = Host(plugin)
            >>> host.load_data()
            >>> print host.to_str('{name} as got IP={ip} and custom data "{my_custom_data}"')
            host_to_be_monitored as got IP=192.168.0.33 and custom data "last check time"
            >>> print host.to_str('Not available data are replaced by a dash: {other_data}')
            Not available data are replaced by a dash: -
            >>> print host.to_str('Or by whatever you want: {other_data}','N/A')
            Or by whatever you want: N/A

            .. note::

                As you noticed, ``NAGIOS_HOSTNAME`` environment variable is stored as ``name`` in
                Host object and ``NAGIOS_HOSTADDRESS`` as ``ip``.
                ``my_custom_data`` is a persistent data that has been
                automatically loaded because set into a previous example.
        """
        return dformat(str,self,defvalue)