@@ -8,13 +8,11 @@ namespace PingCastle.Healthcheck
88{
99 public class HotFixCollector : IHotFixCollector
1010 {
11- private readonly IHotfixService _cimService ;
12- private readonly IHotfixService _wmiService ;
11+ private readonly IHotfixService _hotfixService ;
1312
14- public HotFixCollector ( IHotfixService cimService , IHotfixService wmiService )
13+ public HotFixCollector ( IHotfixService hotfixService )
1514 {
16- _cimService = cimService ?? throw new System . ArgumentNullException ( nameof ( cimService ) ) ;
17- _wmiService = wmiService ?? throw new System . ArgumentNullException ( nameof ( wmiService ) ) ;
15+ _hotfixService = hotfixService ?? throw new System . ArgumentNullException ( nameof ( hotfixService ) ) ;
1816 }
1917
2018 public HotfixQueryResult GetInstalledHotfixes ( string hostName , bool isPrivilegedMode = true , CancellationToken cancellationToken = default )
@@ -35,36 +33,17 @@ public HotfixQueryResult GetInstalledHotfixes(string hostName, bool isPrivileged
3533 return new HotfixQueryResult { Status = HotfixQueryStatus . ConnectionFailed , FailureReason = "Invalid hostname" } ;
3634 }
3735
38- var cimResult = _cimService . TryGetInstalledHotfixes ( hostName , ui , cancellationToken ) ;
39- if ( cimResult . Status == HotfixQueryStatus . Success )
36+ var result = _hotfixService . TryGetInstalledHotfixes ( hostName , ui , cancellationToken ) ;
37+ if ( result . Status == HotfixQueryStatus . Success )
4038 {
41- Trace . WriteLine ( $ "CIM succeeded for { hostName . SanitizeForLog ( ) } with { cimResult . KbNumbers . Count } hotfixes") ;
42- return cimResult ;
39+ Trace . WriteLine ( $ "Retrieved { result . KbNumbers . Count } hotfixes from { hostName . SanitizeForLog ( ) } ") ;
4340 }
44-
45- Trace . WriteLine ( $ "CIM failed for { hostName . SanitizeForLog ( ) } with status { cimResult . Status } : { cimResult . FailureReason } ") ;
46-
47- if ( cimResult . Status == HotfixQueryStatus . AccessDenied )
48- {
49- Trace . WriteLine ( $ "Skipping WMI fallback for { hostName . SanitizeForLog ( ) } - same credentials would fail") ;
50- return cimResult ;
51- }
52-
53- if ( cimResult . Status == HotfixQueryStatus . ConnectionFailed || cimResult . Status == HotfixQueryStatus . Timeout || cimResult . Status == HotfixQueryStatus . NoResults )
41+ else
5442 {
55- Trace . WriteLine ( $ "Attempting WMI fallback for { hostName . SanitizeForLog ( ) } ") ;
56- var wmiResult = _wmiService . TryGetInstalledHotfixes ( hostName , ui , cancellationToken ) ;
57- if ( wmiResult . Status == HotfixQueryStatus . Success )
58- {
59- Trace . WriteLine ( $ "WMI fallback succeeded for { hostName . SanitizeForLog ( ) } with { wmiResult . KbNumbers . Count } hotfixes") ;
60- return wmiResult ;
61- }
62-
63- Trace . WriteLine ( $ "WMI fallback also failed for { hostName . SanitizeForLog ( ) } with status { wmiResult . Status } : { wmiResult . FailureReason } ") ;
64- return wmiResult ;
43+ Trace . WriteLine ( $ "Hotfix detection failed for { hostName . SanitizeForLog ( ) } with status { result . Status } : { result . FailureReason } ") ;
6544 }
6645
67- return cimResult ;
46+ return result ;
6847 }
6948 }
7049}
0 commit comments