예제 #1
0
        //processing discovery rule for zabbix
        public string CVGetClientsForDiscovery()
        {
            string json;
            cvapi  api = new cvapi();

            api.CVGetClients();

            List <cvapi_server> clients = api.CVGetClients();

            List <cvapi_server_subclient> srv_subcl_cid = new List <cvapi_server_subclient>();

            foreach (cvapi_server client_id in clients)
            {
                cv_subclients lst_subclients = api.GetSubClients(Convert.ToInt32(client_id.clientid));
                foreach (string sub_client in lst_subclients.lst_subclients)
                {
                    cvapi_server_subclient new_item = new cvapi_server_subclient
                    {
                        hostname  = client_id.hostname,
                        clientid  = client_id.clientid,
                        subclient = sub_client
                    };
                    srv_subcl_cid.Add(new_item);
                }
            }

            json = JsonConvert.SerializeObject(srv_subcl_cid, Newtonsoft.Json.Formatting.Indented);

            json = json.Replace("\"hostname\"", "\"{#HOSTNAME_CMVLT}\"");
            json = json.Replace("\"clientid\"", "\"{#CLIENTID_CMVLT}\"");
            json = json.Replace("\"subclient\"", "\"{#SUBCLIENT_CMVLT}\"");

            return(json);
        }
예제 #2
0
        //Get all subclients for specified clientid

        public cv_subclients GetSubClients(int cid)
        {
            string token = GetSessionToken(domain, user, pwd);

            cv_subclients subclient = new cv_subclients();

            string clientPropService = service + "/Subclient?clientId=" + cid;

            HttpWebResponse ClientResp = SendRequest(clientPropService, "GET", token, null);

            if (ClientResp.StatusCode == HttpStatusCode.OK)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(ClientResp.GetResponseStream());

                var subclients = xmlDoc.SelectNodes("/App_GetSubClientPropertiesResponse/subClientProperties/*");
                if (subclients != null)
                {
                    foreach (XmlNode cl in subclients)
                    {
                        if (cl.Name == "subClientEntity") //appName="SQL Server"
                        {
                            if (filter_subclient_app.Contains(cl.Attributes["appName"].Value))
                            {
                                subclient.lst_subclients.Add(cl.Attributes["subclientName"].Value.ToUpper());
                            }
                        }
                    }
                }
            }
            return(subclient);
        }