It's possible something like this is already posted since I haven't had a chance to read everything yet, but I found adding these sync template buttons extremely useful when working with 450 some odd servers.
(I have an accompanying non-PHP perl script to wipe out all non-template actions,triggers,functions,items,etc - what I would do is create the host to template linkages, modify the templates accordingly, erase the existing setup, and then use these sync buttons to push everything out).
If there is a forum with other solutions less crude
pls let me know.
Thx,
Matt
Additions to include/config.inc.php:
=================================================
function sync_all_hosts_with_templates()
{
$sql="select * from hosts where port=10050";
$result=DBselect($sql);
while($row=DBfetch($result))
{
sync_host_with_templates($row["hostid"]);
}
}
function sync_all_hosts_with_template($templateid)
{
$sql="select * from hosts_templates where templateid=$templateid";
$result=DBselect($sql);
while($row=DBfetch($result))
{
sync_host_with_template($row["hostid"],$templateid,$row["items"],$row["triggers"],$row["actions"],
$row["graphs"],$row["screens"]);
}
}
=================================================
Additions to hosts.php:
=================================================
if($_GET["register"]=="sync all hosts that use this template")
{
$result=sync_all_hosts_with_template($_GET["host_templateid"]);
show_messages($result, S_ITEMS_ADDED, S_CANNOT_ADD_ITEMS);
unset($_GET["hostid"]);
}
if($_GET["register"]=="sync all hosts with all linked templates")
{
$result=sync_all_hosts_with_templates();
show_messages($result, S_ITEMS_ADDED, S_CANNOT_ADD_ITEMS);
unset($_GET["hostid"]);
}
if($_GET["register"]=="sync this host with all linked templates")
{
$result=sync_host_with_templates($_GET["hostid"]);
show_messages($result, S_ITEMS_ADDED, S_CANNOT_ADD_ITEMS);
unset($_GET["hostid"]);
}
#........................add these buttons where other change host buttons are
echo "input class=\"button\" type=\"submit\" name=\"register\" value=\"sync all hosts with all linked templates\"";
echo "input class=\"button\" type=\"submit\" name=\"register\" value=\"sync this host with all linked templates\"";
echo "input class=\"button\" type=\"submit\" name=\"register\" value=\"sync all hosts that use this template\"";
=================================================
(I have an accompanying non-PHP perl script to wipe out all non-template actions,triggers,functions,items,etc - what I would do is create the host to template linkages, modify the templates accordingly, erase the existing setup, and then use these sync buttons to push everything out).
If there is a forum with other solutions less crude
pls let me know.Thx,
Matt
Additions to include/config.inc.php:
=================================================
function sync_all_hosts_with_templates()
{
$sql="select * from hosts where port=10050";
$result=DBselect($sql);
while($row=DBfetch($result))
{
sync_host_with_templates($row["hostid"]);
}
}
function sync_all_hosts_with_template($templateid)
{
$sql="select * from hosts_templates where templateid=$templateid";
$result=DBselect($sql);
while($row=DBfetch($result))
{
sync_host_with_template($row["hostid"],$templateid,$row["items"],$row["triggers"],$row["actions"],
$row["graphs"],$row["screens"]);
}
}
=================================================
Additions to hosts.php:
=================================================
if($_GET["register"]=="sync all hosts that use this template")
{
$result=sync_all_hosts_with_template($_GET["host_templateid"]);
show_messages($result, S_ITEMS_ADDED, S_CANNOT_ADD_ITEMS);
unset($_GET["hostid"]);
}
if($_GET["register"]=="sync all hosts with all linked templates")
{
$result=sync_all_hosts_with_templates();
show_messages($result, S_ITEMS_ADDED, S_CANNOT_ADD_ITEMS);
unset($_GET["hostid"]);
}
if($_GET["register"]=="sync this host with all linked templates")
{
$result=sync_host_with_templates($_GET["hostid"]);
show_messages($result, S_ITEMS_ADDED, S_CANNOT_ADD_ITEMS);
unset($_GET["hostid"]);
}
#........................add these buttons where other change host buttons are
echo "input class=\"button\" type=\"submit\" name=\"register\" value=\"sync all hosts with all linked templates\"";
echo "input class=\"button\" type=\"submit\" name=\"register\" value=\"sync this host with all linked templates\"";
echo "input class=\"button\" type=\"submit\" name=\"register\" value=\"sync all hosts that use this template\"";
=================================================
Comment