function write_to_hostgroup_yml() { global $server_cfg, $game, $current_yaml_file; // Creating a copy of current yaml file $hostgroupConfigObj = new HostgroupConfig($server_cfg, $game); $current_yaml_file = $hostgroupConfigObj->load_hostgroup_config(); $final_array = json_decode($_POST["json_final"], true); foreach ($final_array as $regex => $config) { if (!isset($config["class"])) { $final_array[$regex] = ""; } } $file_path = sprintf($server_cfg["hostgroups_config"], $game); $yaml_str = Spyc::YAMLDump($final_array); file_put_contents($file_path, $yaml_str) or die("Unable to modify hostgroup.yml file. Exiting...."); }
public function get_host_count_per_class($deploy_id, $game_name) { $hostConfigObj = new HostgroupConfig($this->server_cfg, $game_name); $hostgroup_config = $hostConfigObj->load_hostgroup_config(); $params = array(); $return = array(); foreach ($hostgroup_config as $name => $conf) { if (!isset($conf['class'])) { continue; } $like = str_replace(".*", "%", $name); $pool = str_replace(".*", "", $name); if (isset($conf['hostname_like'])) { //until we have a fix hostgroup corresponding to each hostname $like = $conf['hostname_like']; } if (isset($conf['hostname_not_like'])) { //until we have a fix hostgroup corresponding to each hostname $not_like = $conf['hostname_not_like']; } $query = @"select count(hostname) as count from instances where hostname like '{$like}' and \n\t\t\t\t\thostname not like '{$not_like}' and hostname not like '%bad' and status!='STOPPED' and deploy_id={$deploy_id}"; $stmt = $this->prepare($query); $rows = $this->fetchAll($stmt, $params); $tmp = array(); if (!isset($return[$conf['class']])) { $return[$conf['class']] = array(); } $return[$conf['class']][$pool] = $rows[0]['count']; } foreach ($return as $class => $pool) { $total = 0; foreach ($pool as $name => $count) { $total += $count; } $return[$class]['total'] = $total; } return $return; }
<td><input type="submit" name="submit" value="Submit" id="tag_submit"/></td> </tr> </table> </div> </form> <?php include_once "slack_api.php"; function get_instance_count_slack_offset($game_name) { $slack_api = json_decode(calculate_slack($game_name, false), true); return $slack_api; } $metric_array_map = array("common_web_eu" => "web", "common_mc_eu" => "mc", "common_mb_eu" => "mb", "common_db_eu" => "db", "common_proxy_eu" => "proxy", "common_msched_eu" => "msched", "common_mqueue_eu" => "mqueue", "common_nagios_eu" => "nagios", "common_consumer_eu" => "consumer", "common_gib_web" => "gib"); $hostgroupConfigObj = new HostgroupConfig($server_cfg, $game); $yaml_array = $hostgroupConfigObj->load_hostgroup_config(); $final_yaml_array = array(); $common_config_array = array(); foreach ($yaml_array as $key => $yaml_str) { if (!isset($yaml_str["class"]) and $metric_array_map[$key] != NULL) { $common_config_array[$metric_array_map[$key]] = $yaml_str; continue; } $final_yaml_array[$key] = $yaml_str; if ($final_yaml_array[$key]['hostgroup'] == '') { $final_yaml_array[$key]['hostgroup'] = str_replace(".*", '', $key); } } $json_final_array = json_encode($final_yaml_array); $json_common_config_array = json_encode($common_config_array); $yaml_str = Spyc::YAMLDump($final_yaml_array);
private function load_config($game) { $return = array(); if (empty($game)) { return $return; } $hostgroupConfigObj = new HostgroupConfig($this->server_cfg, $game); return $hostgroupConfigObj->load_hostgroup_config(); }
public function get_configs() { $hostgroupConfigObj = new HostgroupConfig($this->server_cfg, $this->game); //$common_config = $this->server_cfg['common_config_file']; //$hostgroup_config = sprintf($this->server_cfg['hostgroups_config'], $this->game); //$str_yaml = @file_get_contents($common_config); //$str_yaml .= @file_get_contents($hostgroup_config); //$config = load_config($str_yaml); //return $config; return $hostgroupConfigObj->load_hostgroup_config(); }
public function get_hosts_config($game_cfg) { /* $config_dir = sprintf($this->server_cfg['config_directory'], $game_cfg['name']); */ $hostgroupConfigObj = new HostgroupConfig($this->server_cfg, $game_cfg['name']); /*$common_config = $this->server_cfg['common_config_file']; $game_config = sprintf($this->server_cfg['hostgroups_config'], $game_cfg['name']); $str_yml = @file_get_contents($common_config); $str_yml .= @file_get_contents($game_config); $cfg = Spyc::YAMLLoad($str_yml); return $cfg; */ return $hostgroupConfigObj->load_hostgroup_config(); }