This part of the Concierge Paradigm concerns how we coordinate the scaling of our services.
The Concierge acting in the role of concierge_scheduler.sh is taking a request from its client to manage their business schedule. As such when some particular resource gets low, order some more; and when something is no longer being used, get rid of it.
Set the following environment variables in the docker-compose.yml file for the Zabbix server service:
ZBX_API_HOST: The Zabbix web frontend endpoint
ZBX_API_USER: A Zabbix username to access the web API
ZBX_API_PASS: Password for the above Zabbix username, or absolute path to password file
ZBX_CONFIG_DIR: The source path for the Zabbix backup/export files
ZBX_TLS_VERIFY: 'true' to enable ssl verification (default), 'false' to disable
ZBX_FORCE_TEMPLATES: Will delete all templates in destination zabbix server before importing configuration.
Setting to anything other than 'false' will enable this. Can also use the --force-templates flag
GCP_CREDENTIAL_FILE: Credential file of GCP service account for cloud storage
STORAGE_LOCATION: Remote storage location to store configuration files in.
E.g. Cloud Storage bucket name or Azure Container
STORAGE_FOLDER: Folder within bucket/container to upload files to
Example:
ZBX_API_HOST: "zbxweb.svc.eb49da3d-7240-6e94-8e93-b65f3954c652.us-east-1.triton.zone"
ZBX_USER: "Admin"
ZBX_PASS: "zabbix"
ZBX_CONFIG_DIR: "/usr/lib/zabbix/app_config"
Set the following environment variables in the docker_env.py file:
DOCKER_CERT_PATH: The path where the certificates will be generated
DOCKER_HOST: The Docker service API endpoint
COMPOSE_HTTP_TIMEOUT: The time a request to the Docker daemon is allowed to hang before Compose considers it failed
Example:
DOCKER_CERT_PATH = "/tmp/certs"
DOCKER_HOST = "tcp://us-east-1.docker.joyent.com:2376"
DOCKER_CLIENT_TIMEOUT = 800
COMPOSE_HTTP_TIMEOUT = 800
Actions known to the scheduler include the following:
-
list: this action will run
docker-compose psand provide a list of what containers are currently running.It takes two arguments:
list+<component>Example:
concierge_scheduler list consulLogic insight:
Given a component (e.g: consul), functions
pre_pem_fileandgenerate_pem_fileconstruct certificates from the inventory of a component dummy host containing the relevant data and call functionlistto provide the list of running containers. Once the result is provided the certificates will be deleted. -
backup_config: this action will make an export of the below components existing in Zabbix.
List of components: templates, hostgroups, hosts, mediatypes, auto-registration actions and triggers actions.
It only takes one argument:
backup_configExample:
concierge_scheduler backup_configLogic insight:
Different Zabbix API methods are used to export components.
- Function
export_templatesexports all templates configuration data to filetemplates.jsonusing the configuration.export method. - Function
export_host_groupsexports all hostgroups configuration data to filehostgroups.jsonusing the configuration.export method. - Function
export_hostsexports all hosts configuration data to filehostgroups.jsonusing the configuration.export method. - Function
export_media_typesexports all mediatypes configuration data to filemediatypes.jsonusing the get method. - Function
export_auto_registration_actionsexports all auto-registration actions configuration data to filereg_actions.jsonusing the get method. - Function
export_trigger_actionsexports all trigger actions configuration data to filetrigger_actions.jsonusing the get method. - Function
export_actions_dataexport all templates and hostgroups names and IDs to fileactions_data_orig.jsonusing get methods. This file can later be used to import auto-registration actions.
- Function
-
restore_config: this action will make an import of the below components using a set of backup files as source from the assigned configuration directory.
List of components: hostgroups, templates, hosts, auto-registration actions, triggers actions, mediatypes.
It only takes one argument:
restore_configExample:
concierge_scheduler restore_configIt also takes the flag:
--force-templateswhich will force all templates on destination server to be deleted before importing the template configurationLogic insight:
Different Zabbix API methods are used to import components.
- Function
import_hostgroupsimports all hostgroups configuration data from filehostgroups.jsonusing the configuration.import method. - Function
import_templatesimports all templates configuration data from filetemplates.jsonusing the configuration.import method. - Function
import_hostsimports all hosts configuration data from filehosts.jsonusing the configuration.import method. - Function
import_reg_actionsimports all auto-registration actions configuration data from filereg_actions_import.jsonusing the create method. As we don't know beforehand which IDs will have thetemplatesandhostgroupscreated by the above imports and these are necessary to create the auto-registration actions we use the following approach:- Generate the json file
actions_data_dest.jsonwithhostgroupsandtemplatesinfo from the destination Zabbix server (where the import is happening) using the__exp_act_data_destfunction. We already have the json fileactions_data_orig.jsonwithhostgroupsandtemplatesinfo from the origin Zabbix server (where the backup/export was done). - Loop through the
reg_actions.jsonbackup file using function__get_autoreg_action_dictto replace the originhostgroupandtemplateIDs with the destination IDs using the above generated files and constructing the filereg_actions_import.jsonwith the result. Some unnecessary keys are also removed while looping through the file. - Import the auto-registration actions making a request to the action.create method using the newly generated
reg_actions_import.jsonfile.
- Generate the json file
- Function
import_trig_actionsimports all trigger actions configuration data from filetrigger_actions_import.jsonusing the create method. Some unnecessary keys are removed from the backup filetrigger_actions.jsonusing function__get_trigger_action_dictwhich generates the desired filetrigger_actions_import.json. - Function
import_mediatypesimports all mediatypes configuration data from filemediatypes.jsonusing the configuration.import method. - Function
import_servicesimports all services configuration data from fileservices.jsonusing the create method. - Function
import_proxiesimports all proxy configuration data from fileproxies.jsonusing the create method.
- Function
-
scale_up: this action will increment the number of containers on a selected component.
It takes four arguments:
scale_up+<component>+<current_scale>+<increment>Example:
concierge_scheduler scale_up consul 1 1Logic insight:
Given a component (e.g: consul) which needs to be scaled up, functions
pre_pem_fileandgenerate_pem_fileconstruct certificates from the inventory of a component dummy host containing the relevant data and call functionscale_upwith the current number of containers for the component (current_scale) and the number we want to add (increment). Once the component is incremented to the desired scale the certificates will be deleted. -
scale_down: this action will decrease the number of containers on a selected component.
It takes four arguments:
scale_up+<component>+<current_scale>+<decrement>Example:
concierge_scheduler scale_down consul 2 1Logic insight:
Given a component (e.g: consul) which needs to be scaled down, functions
pre_pem_fileandgenerate_pem_fileconstruct certificates from the inventory of a component dummy host containing the relevant data and call functionscale_downwith the current number of containers for the component (current_scale) and the number we want to reduce (decrement). Once the component is decremented to the desired scale the certificates will be deleted. -
upload: this action will upload files in specified config directory to a cloud storage location. Defaults to using GCP Cloud Storage.
To perform actions using the concierge_scheduler image, the required environment variables must be set,
and actions performed using command below. Note: Actions will be performed in order b->r->u->d
regardless of command combination order (e.g. -bud will be performed in same order as -dub)
-b: runbackup_config-r: runrestore_config-u: runupload-d: deleteZBX_CONFIG_DIR(after running other commands)
Using docker run to perform restore_config:
docker create -e ZBX_CONFIG_DIR=/config-dir --env-file .env-file mesoform/concierge_scheduler -rUsing docker-compose.yml to perform backup_config, then upload to cloud :
service:
concierge_scheduler:
image: mesoform/concierge_scheduler
env-file:
- .env-file
environment:
- ZBX_CONFIG_DIR=/config-dir
command: ["-bu"]The scheduler can be used outside the concierge paradigm to perform Zabbix configuration import/exports. Some external libraries are required performing actions:
pyzabbix: Required for Zabbix API usage- (Optional)
google-auth: Required for authentication with GCP - (Optional)
google-cloud-storage: Required for uploading files to GCS
Backing up existing zabbix configuration:
export ZBX_CONFIG_DIR=/zbx-config/
export ZBX_API_USER="Admin"
export ZBX_API_HOST="http://company-zabbix-frontend.com/"
export ZBX_API_PASS="zabbix"
export ZBX_TLS_VERIFY='false'
##Backup existing configuration
python concierge_scheduler.py event backup_config
##Restore configuration from configuration files
python concierge_scheduler.py event restore_config
##Upload ZBX_CONFIG_DIR to GCS bucket
export GCP_CREDENTIAL_FILE=/credentials-file.json
export STORAGE_LOCATION=gcs-bucket-name
export STORAGE_FOLDER=subfolder-for-config-folders
python concierge_scheduler.py cloud upload- With container infrastructures, like Joyent's Triton, that manage placement of containers and allow containers to be first-class citizen's on the host and network, simply running docker-compose will be fine. However, when running containers on other infrastructures you may need to perform a little extra work to set up Docker Engine in Swarm Mode and scale services using docker service.
- If using scheduler for importing zabbix configuration, do not use in a server where existing configuration is needed. Importing configuration will remove the existing configuration.