Beispiel #1
0
 /// <summary>
 /// Get Traffic Groups
 /// </summary>
 private static void GetGroupsForStandaloneDevices()
 {
     // Go Through Each Device
     foreach (f5Device device in DeviceList)
     {
         if (device.Standalone)
         {
             // Create a Dummy Device Group (to keep the layout)
             SyncFailoverGroup newDeviceGroup = new SyncFailoverGroup();
             newDeviceGroup.Name = device.SystemNodeName;
             newDeviceGroup.Type = "Sync-Failover";
             newDeviceGroup.DeviceList.Add(device);
             newDeviceGroup.Standalone  = true;
             newDeviceGroup.Addresses   = device.Address;
             newDeviceGroup.Communities = device.Community;
             newDeviceGroup.Ports       = device.Port.ToString();
             foreach (string tg in device.ActiveTrafficGroups)
             {
                 TrafficGroup newTrafficGroup = new TrafficGroup();
                 newTrafficGroup.Name     = tg.Substring(tg.LastIndexOf("/") + 1);
                 newTrafficGroup.FullName = tg;
                 newTrafficGroup.Key      = tg + "-" + device.SerialNumber;
                 newTrafficGroup.Devices  = device.SystemNodeName;
                 newTrafficGroup.CreateScomObject();
                 newDeviceGroup.TrafficGroupList.Add(newTrafficGroup);
             }
             SyncFailoverGroupList.Add(newDeviceGroup);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Get Virtual Servers, Pools, PoolMembers, Profiles and Certificates from Group
        /// </summary>
        /// <param name="devGroup">Group to Collect Info From</param>
        private static void GetObjectsFromDeviceGroup(SyncFailoverGroup sfog)
        {
            // Create Common Partition Holder
            Partition CommonPartition = new Partition("Blank", "Blank");

            // Attach to First Device in Device Group
            m_interfaces.initialize(sfog.DeviceList[0].Address, sfog.DeviceList[0].F5usr, sfog.DeviceList[0].F5pwd);

            if (m_interfaces.initialized)
            {
                // Get SNMP Info (Not Partition Dependant)
                // Virtual Server
                List <Variable> VirtualServerSnmpResults = SNMP.WalkSNMP(SNMP.ltmVsStatusName, sfog.DeviceList[0].Address, sfog.DeviceList[0].Port, sfog.DeviceList[0].Community);
                // Pools
                List <Variable> PoolSnmpResults = SNMP.WalkSNMP(SNMP.ltmPoolStatusName, sfog.DeviceList[0].Address, sfog.DeviceList[0].Port, sfog.DeviceList[0].Community);
                // Pool Members
                List <Variable> PoolMemberSnmpResults = SNMP.WalkSNMP(SNMP.ltmPoolMbrStatusNodeName, sfog.DeviceList[0].Address, sfog.DeviceList[0].Port, sfog.DeviceList[0].Community);
                // Client SSL Profiles
                List <Variable> ClientSslProfileSnmpResults = SNMP.WalkSNMP(SNMP.ltmClientSslName, sfog.DeviceList[0].Address, sfog.DeviceList[0].Port, sfog.DeviceList[0].Community);
                // Server SSL Profiles
                List <Variable> ServerSslProfileSnmpResults = SNMP.WalkSNMP(SNMP.ltmServerSslName, sfog.DeviceList[0].Address, sfog.DeviceList[0].Port, sfog.DeviceList[0].Community);

                // Get List of Partitions
                ManagementPartitionAuthZPartition[] partitionList = m_interfaces.ManagementPartition.get_partition_list();

                // Loop through Partitions
                foreach (ManagementPartitionAuthZPartition partition in partitionList)
                {
                    // Set Active Partition
                    m_interfaces.ManagementPartition.set_active_partition(partition.partition_name);

                    // Create Partition
                    Partition newPartition = new Partition(sfog.Key, partition.partition_name);
                    sfog.PartitionList.Add(newPartition);

                    // Get Certificates
                    ManagementKeyCertificateCertificateInformation_v2[] certs = m_interfaces.ManagementKeyCertificate.get_certificate_list_v2(ManagementKeyCertificateManagementModeType.MANAGEMENT_MODE_DEFAULT);
                    foreach (ManagementKeyCertificateCertificateInformation_v2 cert in certs)
                    {
                        Certificate newCert = new Certificate(cert, sfog, partition.partition_name);
                        newPartition.CertificateList.Add(newCert);
                    }

                    // Get Client SSL Profiles
                    // Get iControl Info
                    string[] ProfileClientSSLList                    = m_interfaces.LocalLBProfileClientSSL.get_list();
                    string[] ProfileClientSSLDescriptionList         = m_interfaces.LocalLBProfileClientSSL.get_description(ProfileClientSSLList);
                    LocalLBProfileString[] ProfileClientSSL_ca_files = m_interfaces.LocalLBProfileClientSSL.get_certificate_file_v2(ProfileClientSSLList);

                    // Loop Through All Client SSL profiles
                    for (int i = 0; i < ProfileClientSSLList.Length; i++)
                    {
                        // Create Profile
                        ProfileClientSSL newProfile = new ProfileClientSSL(sfog, partition.partition_name, ProfileClientSSLList[i], ProfileClientSSLDescriptionList[i], ProfileClientSSL_ca_files[i].value);

                        // Look for Matching Certs in This Partition
                        foreach (Certificate cert in newPartition.CertificateList)
                        {
                            if (ProfileClientSSL_ca_files[i].value == cert.SCOM_Object.Values[3].ToString())
                            {
                                newProfile.CertificateList.Add(cert);
                            }
                        }

                        // Look For Matching Certificates in Common Partition
                        if (partition.partition_name != "Common")
                        {
                            foreach (Certificate cert in CommonPartition.CertificateList)
                            {
                                if (ProfileClientSSL_ca_files[i].value == cert.SCOM_Object.Values[3].ToString())
                                {
                                    newProfile.CertificateList.Add(cert);
                                }
                            }
                        }

                        // Save ClientSslProfile
                        newPartition.ClientSslProfileList.Add(newProfile);
                    }

                    // Get Server SSL Profiles
                    string[] ProfileServerSSLList                    = m_interfaces.LocalLBProfileServerSSL.get_list();
                    string[] ProfileServerSSLDescriptionList         = m_interfaces.LocalLBProfileServerSSL.get_description(ProfileServerSSLList);
                    LocalLBProfileString[] ProfileServerSSL_ca_files = m_interfaces.LocalLBProfileServerSSL.get_certificate_file_v2(ProfileServerSSLList);
                    // Loop Through All Server SSL profiles
                    for (int i = 0; i < ProfileServerSSLList.Length; i++)
                    {
                        // Create Profile
                        ProfileServerSSL newProfile = new ProfileServerSSL(sfog, partition.partition_name, ProfileServerSSLList[i], ProfileServerSSLDescriptionList[i], ProfileServerSSL_ca_files[i].value);
                        // Look for Matching Certs in This Partition
                        foreach (Certificate cert in newPartition.CertificateList)
                        {
                            if (ProfileServerSSL_ca_files[i].value == cert.SCOM_Object.Values[3].ToString())
                            {
                                newProfile.CertificateList.Add(cert);
                            }
                        }

                        // Look For Matching Certificates in Common Partition
                        if (partition.partition_name != "Common")
                        {
                            foreach (Certificate cert in CommonPartition.CertificateList)
                            {
                                if (ProfileServerSSL_ca_files[i].value == cert.SCOM_Object.Values[3].ToString())
                                {
                                    newProfile.CertificateList.Add(cert);
                                }
                            }
                        }
                        newPartition.ServerSslProfileList.Add(newProfile);
                    }

                    // Get Virtual Servers
                    // Get iControl Info
                    string[] vipNames        = m_interfaces.LocalLBVirtualServer.get_list();
                    string[] vipDefaultPools = m_interfaces.LocalLBVirtualServer.get_default_pool_name(vipNames);
                    LocalLBVirtualServerVirtualServerType[] vipTypes = m_interfaces.LocalLBVirtualServer.get_type(vipNames);
                    CommonAddressPort[] vipAddressPorts     = m_interfaces.LocalLBVirtualServer.get_destination_v2(vipNames);
                    string[]            vipDescriptions     = m_interfaces.LocalLBVirtualServer.get_description(vipNames);
                    CommonULong64[]     vipConnectionLimits = m_interfaces.LocalLBVirtualServer.get_connection_limit(vipNames);
                    LocalLBVirtualServerVirtualServerProfileAttribute[][] vipProfiles = m_interfaces.LocalLBVirtualServer.get_profile(vipNames);

                    // Loop Through All Virtual Servers
                    for (int i = 0; i < vipNames.Length; i++)
                    {
                        // Set Address
                        string vipAddress = vipAddressPorts[i].address;
                        vipAddress = vipAddress.Substring(vipAddress.LastIndexOf("/") + 1);
                        // Get Connection Limit
                        string vipConnectionLimit = ConvertUlong(vipConnectionLimits[i]).ToString();
                        // Get Oid Suffix
                        string vipOidSuffix = GetOidSuffix(vipNames[i], SNMP.ltmVsStatusName, VirtualServerSnmpResults);
                        // Get Client SSL Profiles
                        string vipClientSSLProfiles = "";
                        string vipServerSSLProfiles = "";
                        foreach (LocalLBVirtualServerVirtualServerProfileAttribute profileAttr in vipProfiles[i])
                        {
                            if (profileAttr.profile_type == LocalLBProfileType.PROFILE_TYPE_CLIENT_SSL)
                            {
                                vipClientSSLProfiles += profileAttr.profile_name + ",";
                            }
                            if (profileAttr.profile_type == LocalLBProfileType.PROFILE_TYPE_SERVER_SSL)
                            {
                                vipServerSSLProfiles += profileAttr.profile_name + ",";
                            }
                        }
                        vipClientSSLProfiles = vipClientSSLProfiles.TrimEnd(',');
                        vipServerSSLProfiles = vipServerSSLProfiles.TrimEnd(',');
                        // Get Device Group
                        string vipDeviceGroup = sfog.Name;

                        VirtualServer vs = new VirtualServer(sfog, partition.partition_name, vipNames[i], vipAddress, vipAddressPorts[i].port.ToString(), vipDescriptions[i],
                                                             vipTypes[i].ToString(), vipDefaultPools[i], vipConnectionLimit, vipClientSSLProfiles, vipServerSSLProfiles);

                        // Look For Matching ClientSslProfiles in this Partition
                        foreach (ProfileClientSSL profile in newPartition.ClientSslProfileList)
                        {
                            if (vipClientSSLProfiles.Contains(profile.SCOM_Object.Values[0].ToString()))
                            {
                                vs.ProfileClientSslList.Add(profile);
                            }
                        }
                        // Look For Matching ClientSslProfiles in Common Partition
                        if (partition.partition_name != "Common")
                        {
                            foreach (ProfileClientSSL profile in CommonPartition.ClientSslProfileList)
                            {
                                if (vipClientSSLProfiles.Contains(profile.SCOM_Object.Values[0].ToString()))
                                {
                                    vs.ProfileClientSslList.Add(profile);
                                }
                            }
                        }
                        // Look For Matching ServerSslProfiles in this Partition
                        foreach (ProfileServerSSL profile in newPartition.ServerSslProfileList)
                        {
                            if (vipServerSSLProfiles.Contains(profile.SCOM_Object.Values[0].ToString()))
                            {
                                vs.ProfileServerSslList.Add(profile);
                            }
                        }
                        // Look For Matching ClientSslProfiles in Common Partition
                        if (partition.partition_name != "Common")
                        {
                            foreach (ProfileServerSSL profile in CommonPartition.ServerSslProfileList)
                            {
                                if (vipServerSSLProfiles.Contains(profile.SCOM_Object.Values[0].ToString()))
                                {
                                    vs.ProfileServerSslList.Add(profile);
                                }
                            }
                        }
                        // Add it to the List
                        newPartition.VirtualServerList.Add(vs);
                    }

                    // Get Pools & Pool Members
                    // Get iControl Info
                    string[] poolNames                           = m_interfaces.LocalLBPool.get_list();
                    string[] poolDescriptions                    = m_interfaces.LocalLBPool.get_description(poolNames);
                    long[]   poolActiveMemberCount               = m_interfaces.LocalLBPool.get_active_member_count(poolNames);
                    CommonAddressPort[][] poolMembers            = m_interfaces.LocalLBPool.get_member_v2(poolNames);
                    string[][]            poolMemberDescriptions = m_interfaces.LocalLBPool.get_member_description(poolNames, poolMembers);
                    // Loop Through All Pools
                    for (int i = 0; i < poolNames.Length; i++)
                    {
                        // Get Full Name
                        string sPoolName = poolNames[i];

                        // Get Node Short Name
                        string sShortPoolName = sPoolName.Substring(sPoolName.LastIndexOf("/") + 1);

                        // Ignore _auto_ Nodes
                        if (sShortPoolName.ToLower().StartsWith("_auto_"))
                        {
                            continue;
                        }

                        // Get Oid Suffix
                        string OidSuffix = GetOidSuffix(sPoolName, SNMP.ltmPoolStatusName, PoolSnmpResults);

                        // Get Monitor Rule
                        string MonitorRule = SNMP.GetSNMP(SNMP.ltmPoolMonitorRule + OidSuffix, sfog.DeviceList[0].Address, sfog.DeviceList[0].Port, sfog.DeviceList[0].Community)[0].Data.ToString();

                        // Create new Pool
                        Pool newPool = new Pool(sfog, partition.partition_name, sPoolName, sShortPoolName, poolDescriptions[i], MonitorRule, poolMembers[i].Length, poolActiveMemberCount[i]);

                        // Add Pool Members
                        for (int j = 0; j < poolMembers[i].Length; j++)
                        {
                            // Get Oid Suffix
                            string pmOidSuffix = GetOidSuffix(poolMembers[i][j].address, SNMP.ltmPoolMbrStatusNodeName, PoolMemberSnmpResults);
                            // Get Monitor Rule (using SNMP as iControl seems to Error)
                            string pmMonitorRule = SNMP.GetSNMP(SNMP.ltmPoolMemberMonitorRule + pmOidSuffix, sfog.DeviceList[0].Address, sfog.DeviceList[0].Port, sfog.DeviceList[0].Community)[0].Data.ToString();

                            // Create New Pool Member
                            PoolMember newPoolMember = new PoolMember(sfog, partition.partition_name, sPoolName, poolMembers[i][j].address, poolMemberDescriptions[i][j], poolMembers[i][j].port.ToString(), pmMonitorRule);

                            // Add to Pool
                            newPool.PoolMembers.Add(newPoolMember);
                        }

                        // Add it to the List
                        newPartition.PoolList.Add(newPool);

                        // Match To Virtual Servers (DefaultPool)
                        foreach (VirtualServer vs in newPartition.VirtualServerList)
                        {
                            if (vs.DefaultPoolName == sPoolName)
                            {
                                vs.DefaultPool = newPool;
                            }
                        }
                    }


                    // Get Nodes
                    string[] nodeNameList        = m_interfaces.LocalLBNodeAddressV2.get_list();
                    string[] nodeAddressList     = m_interfaces.LocalLBNodeAddressV2.get_address(nodeNameList);
                    string[] nodeDescriptionList = m_interfaces.LocalLBNodeAddressV2.get_description(nodeNameList);
                    for (int i = 0; i < nodeNameList.Length; i++)
                    {
                        // Get Node Full Name
                        string sNodeName = nodeNameList[i];

                        // Get Node Short Name
                        string sShortNodeName = sNodeName.Substring(sNodeName.LastIndexOf("/") + 1);

                        // Ignore _auto_ Nodes
                        if (sShortNodeName.ToLower().StartsWith("_auto_"))
                        {
                            continue;
                        }

                        string MonitorRules = "";
                        try
                        {
                            LocalLBMonitorRule[] nodeMonitorRuleList = m_interfaces.LocalLBNodeAddressV2.get_monitor_rule(new string[] { sNodeName });
                            for (int j = 0; j < nodeMonitorRuleList[0].monitor_templates.Length; j++)
                            {
                                MonitorRules += nodeMonitorRuleList[0].monitor_templates[j].ToString() + ",";
                            }
                            MonitorRules = MonitorRules.TrimEnd(',');
                        }
                        catch (Exception)
                        {
                        }

                        // Create a New Node
                        Node newNode = new Node(sfog.Key, partition.partition_name, sNodeName, sShortNodeName, nodeAddressList[i], nodeDescriptionList[i], MonitorRules);
                        newPartition.NodeList.Add(newNode);
                    }

                    // Take a Copy of Common Parition
                    if (partition.partition_name == "Common")
                    {
                        CommonPartition = newPartition;
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get Device Groups
        /// </summary>
        private static void GetDeviceGroups()
        {
            foreach (f5Device device in DeviceList)
            {
                // Show Info
                log.Info(device.Address + "...");

                // Connect to F5 Device via iControl
                m_interfaces.initialize(device.Address, device.F5usr, device.F5pwd);

                // Set active partition to "Common"
                m_interfaces.ManagementPartition.set_active_partition("Common");

                // Get Device Group Names
                string[] devGroupNameList = m_interfaces.ManagementDeviceGroup.get_list();
                ManagementDeviceGroupFailoverStatus failover = m_interfaces.ManagementDeviceGroup.get_failover_status();
                CommonEnabledState[] status = m_interfaces.ManagementDeviceGroup.get_network_failover_enabled_state(devGroupNameList);
                // Check Each Device Group
                foreach (string devGroupFullName in devGroupNameList)
                {
                    // Get array of device names
                    string[] devGroupDeviceNameList = m_interfaces.ManagementDeviceGroup.get_device(new string[] { devGroupFullName })[0];

                    // Sort it
                    Array.Sort(devGroupDeviceNameList, StringComparer.InvariantCulture);

                    // Get Short Name of Current Device
                    string devGroupShortName = devGroupFullName.Substring(devGroupFullName.LastIndexOf("/") + 1);

                    // Ignore gtm, device_trust_group
                    if ((devGroupShortName == "gtm") || (devGroupShortName == "device_trust_group"))
                    {
                        continue;
                    }

                    // Set Key to Short Name of Current Device Group
                    string tempDevGroupKey = devGroupShortName;

                    // Append all Device Names
                    foreach (string devFullName in devGroupDeviceNameList)
                    {
                        tempDevGroupKey += "-" + devFullName.Substring(devFullName.LastIndexOf("/") + 1);
                    }

                    // Set exists to false
                    bool GroupExists = false;

                    // Check Device Group Type (Only Interested in ManagementDeviceGroupType.DGT_FAILOVER)
                    ManagementDeviceGroupType[]       devGroupTypes      = m_interfaces.ManagementDeviceGroup.get_type(new string[] { devGroupFullName });
                    ManagementDeviceGroupSyncStatus[] devGroupSyncStatus = m_interfaces.ManagementDeviceGroup.get_sync_status(new string[] { devGroupFullName });
                    if (devGroupTypes[0] == ManagementDeviceGroupType.DGT_FAILOVER)
                    {
                        // See if We already have this DeviceGroup
                        foreach (SyncFailoverGroup group in SyncFailoverGroupList)
                        {
                            // It Exists
                            if (group.Key == tempDevGroupKey)
                            {
                                // Set Standalone
                                group.Standalone = (devGroupSyncStatus[0].status == "Standalone") ? true : false;
                                // Add Device to DeviceList
                                group.DeviceList.Add(device);
                                // Add New Traffic Group(s)
                                foreach (string tg in device.ActiveTrafficGroups)
                                {
                                    TrafficGroup newTrafficGroup = new TrafficGroup();
                                    newTrafficGroup.DeviceGroup = group;
                                    newTrafficGroup.FullName    = tg;
                                    newTrafficGroup.Name        = tg.Substring(tg.LastIndexOf("/") + 1);
                                    group.TrafficGroupList.Add(newTrafficGroup);
                                }
                                GroupExists = true;
                            }
                        }
                        // If Group Doesn't Exist then Create it
                        if (!GroupExists)
                        {
                            // Create Device Group
                            SyncFailoverGroup newGroup = new SyncFailoverGroup();
                            // Add Device to DeviceList
                            newGroup.DeviceList.Add(device);
                            // Set Standalone
                            newGroup.Standalone = (devGroupSyncStatus[0].status == "Standalone") ? true : false;
                            // Set DeviceGroup Type
                            if (devGroupTypes[0] == ManagementDeviceGroupType.DGT_FAILOVER)
                            {
                                newGroup.Type = "Sync-Failover";
                            }
                            else
                            {
                                newGroup.Type = "Sync-Only";
                            }
                            newGroup.Key  = tempDevGroupKey;
                            newGroup.Name = devGroupFullName.Substring(devGroupFullName.LastIndexOf("/") + 1);
                            // Add New Traffic Group(s)
                            foreach (string tg in device.ActiveTrafficGroups)
                            {
                                TrafficGroup newTrafficGroup = new TrafficGroup();
                                newTrafficGroup.DeviceGroup = newGroup;
                                newTrafficGroup.FullName    = tg;
                                newTrafficGroup.Name        = tg.Substring(tg.LastIndexOf("/") + 1);
                                newGroup.TrafficGroupList.Add(newTrafficGroup);
                            }

                            newGroup.deviceStrings = m_interfaces.ManagementDeviceGroup.get_device(new string[] { devGroupFullName })[0];
                            // Add DeviceGroup to List
                            SyncFailoverGroupList.Add(newGroup);
                        }
                    }
                }
            }

            // Get Device Groups/TrafficGroups for Standalone Devices
            GetGroupsForStandaloneDevices();

            // Log Discoverd Device Groups
            log.Info("Finished Device Group Discovery Found; " + SyncFailoverGroupList.Count.ToString() + " Groups!");

            // Clean up SyncFailover Groups
            foreach (SyncFailoverGroup sfog in SyncFailoverGroupList)
            {
                // Create Comma Seperated Devices String
                foreach (f5Device device in sfog.DeviceList)
                {
                    sfog.Devices += device.SystemNodeName + ',';
                }
                // Trim the last comma from devices
                sfog.Devices = sfog.Devices.TrimEnd(',');

                // Sort Device List by Serial Number (Needed For Making Key)
                sfog.DeviceList.Sort((x, y) => x.SerialNumber.CompareTo(y.SerialNumber));

                // Get Serial Key Suffix
                string KeySuffix = "";

                foreach (string deviceName in sfog.deviceStrings)
                {
                    foreach (EnterpriseManagementObject objDevice in SCOM_DeviceList.Items)
                    {
                        string sFullName = "/common/" + objDevice.DisplayName.ToLower();
                        if (deviceName.ToLower() == sFullName)
                        {
                            sfog.Addresses   += objDevice.Values[2].ToString() + ",";
                            sfog.Ports       += objDevice.Values[3].ToString() + ",";
                            sfog.Communities += objDevice.Values[4].ToString() + ",";
                            KeySuffix        += "-" + objDevice.Values[13].ToString();
                            break;
                        }
                    }
                }


                sfog.Addresses   = sfog.Addresses.TrimEnd(',');
                sfog.Ports       = sfog.Ports.TrimEnd(',');
                sfog.Communities = sfog.Communities.TrimEnd(',');
                // Recalculate Device Group Key
                sfog.Key = sfog.Name + KeySuffix;


                // Sort Traffic Group List by Serial Number (Needed For Making Key)
                foreach (TrafficGroup tg in sfog.TrafficGroupList)
                {
                    tg.Devices = sfog.Devices;
                    tg.Key    += tg.Name + KeySuffix;
                    tg.CreateScomObject();
                }

                // Get Virtual Servers
                log.Info("Collecting Further Information from..." + sfog.Name);
                GetObjectsFromDeviceGroup(sfog);

                // Create SCOM Object for This Device Object
                sfog.CreateDeviceGroupScomObject();
            }
        }