Skip to content

Instantly share code, notes, and snippets.

@akagisho
Created September 18, 2017 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akagisho/258c8615084be77e2273892a62575f74 to your computer and use it in GitHub Desktop.
Save akagisho/258c8615084be77e2273892a62575f74 to your computer and use it in GitHub Desktop.
Import Zabbix's Templates
<?php
require_once 'vendor/autoload.php';
use ZabbixApi\ZabbixApi;
$url = $argv[1];
$user = $argv[2];
$pass = $argv[3];
$file = $argv[4];
try
{
$api = new ZabbixApi($url, $user, $pass);
$source = file_get_contents($file);
$result = $api->configurationImport(array(
'format' => 'xml',
'rules' => array(
'templates' => array('createMissing' => true, 'updateExisting' => true),
'applications' => array('createMissing' => true, 'updateExisting' => true),
'discoveryRules' => array('createMissing' => true, 'updateExisting' => true),
'graphs' => array('createMissing' => true, 'updateExisting' => true),
'groups' => array('createMissing' => true, 'updateExisting' => true),
'hosts' => array('createMissing' => true, 'updateExisting' => true),
'images' => array('createMissing' => true, 'updateExisting' => true),
'items' => array('createMissing' => true, 'updateExisting' => true),
'maps' => array('createMissing' => true, 'updateExisting' => true),
'screens' => array('createMissing' => true, 'updateExisting' => true),
'templateLinkage' => array('createMissing' => true, 'updateExisting' => true),
'templateScreens' => array('createMissing' => true, 'updateExisting' => true),
'triggers' => array('createMissing' => true, 'updateExisting' => true),
'valueMaps' => array('createMissing' => true, 'updateExisting' => true),
),
'source' => $source
));
echo $result;
}
catch(Exception $e)
{
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment