pub async fn find_analyzers(
configuration: &Configuration,
analyzer_find_request: Option<AnalyzerFindRequest>,
) -> Result<Vec<Worker>, Error<FindAnalyzersError>>Examples found in repository?
examples/common.rs (line 64)
53pub async fn get_analyzer_id_by_name(
54 config: &Configuration,
55 analyzer_name_to_find: &str,
56) -> Result<Option<String>, Box<dyn std::error::Error>> {
57 println!(
58 "Fetching all analyzer instances to find ID for '{}'...",
59 analyzer_name_to_find
60 );
61
62 let find_request = Some(cortex_client::models::AnalyzerFindRequest::default());
63
64 match cortex_client::apis::analyzer_api::find_analyzers(config, find_request).await {
65 Ok(analyzer_instances) => {
66 // Directly a Vec<Worker>
67 for analyzer_instance in analyzer_instances {
68 if let Some(name) = &analyzer_instance.name {
69 if name == analyzer_name_to_find {
70 if let Some(id) = analyzer_instance._id {
71 println!(
72 "Found analyzer ID '{}' for name '{}'",
73 id, analyzer_name_to_find
74 );
75 return Ok(Some(id));
76 }
77 }
78 }
79 }
80 println!("Analyzer with name '{}' not found.", analyzer_name_to_find);
81 Ok(None)
82 }
83 Err(e) => {
84 eprintln!("Error fetching analyzer instances: {:?}", e);
85 Err(Box::new(e))
86 }
87 }
88}More examples
examples/list_analyzers.rs (line 62)
49async fn main() -> Result<(), Box<dyn std::error::Error>> {
50 let config = match common::setup_configuration() {
51 Ok(cfg) => cfg,
52 Err(e) => {
53 eprintln!("Configuration error: {}", e);
54 return Err(e.into());
55 }
56 };
57
58 println!("Fetching list of all analyzer instances...");
59
60 let find_request = Some(cortex_client::models::AnalyzerFindRequest::default());
61
62 match analyzer_api::find_analyzers(&config, find_request).await {
63 Ok(analyzers) => {
64 println!("\nSuccessfully fetched analyzer instances:");
65 if analyzers.is_empty() {
66 println!("No analyzer instances found in your Cortex organization.");
67 } else {
68 println!("--------------------------------------------------");
69 println!("Available Analyzer Instances:");
70 println!("--------------------------------------------------");
71 for worker_instance in &analyzers {
72 // Iterate over the direct vector
73 println!(
74 " Name: {}",
75 worker_instance.name.as_deref().unwrap_or("N/A")
76 );
77 println!(
78 " Instance ID (_id): {}", // THIS IS WHAT YOU NEED
79 worker_instance._id.as_deref().unwrap_or("MISSING_ID")
80 );
81 println!(
82 " Definition ID: {}",
83 worker_instance
84 .worker_definition_id
85 .as_deref()
86 .unwrap_or("N/A")
87 );
88 println!(
89 " Type: {:?}",
90 worker_instance
91 .r#type
92 .unwrap_or(cortex_client::models::worker::Type::Analyzer) // Provide a default if None
93 );
94 println!(" Enabled (Implicitly): If listed, it's an instance. Check Cortex UI for explicit enabled/disabled status if unsure.");
95 println!(" ---");
96 }
97 println!("\nTotal analyzer instances found: {}", analyzers.len());
98 println!("--------------------------------------------------");
99 println!("\nLook for your AbuseIPDB analyzer in the list above and use its 'Instance ID (_id)'");
100 println!(
101 "in your abuseipdb_example.rs file for the 'analyzer_worker_id' variable."
102 );
103 }
104 }
105 Err(e) => {
106 eprintln!("\nError fetching analyzer instances: {:?}", e);
107 eprintln!("Please check your Cortex connection and API key permissions.");
108 if let cortex_client::apis::Error::Serde(serde_err) = e {
109 eprintln!("Serde error details: {}", serde_err);
110 }
111 }
112 }
113
114 Ok(())
115}