Post to osTicket on failures too

This commit is contained in:
2Shirt 2026-01-17 14:53:28 -08:00
parent 135ef44feb
commit 049b036e65
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
3 changed files with 89 additions and 53 deletions

View file

@ -87,7 +87,7 @@ impl Component for TicketSelection {
KeyCode::Enter => Some(Action::SetMode(Mode::ScanDisks)),
KeyCode::Esc => Some(Action::DisplayPopup(
PopupType::Question,
String::from("Disable osTicket integration?\n\nY / N"),
String::from("Disable osTicket integration?\n\n\nY / N"),
)),
_ => None,
},

View file

@ -28,6 +28,7 @@ pub enum ReportType {
pub struct OsTicket {
pub connected: bool,
pub disabled: bool,
pub error: String,
pub server_url: String,
pub report: Vec<String>,
pub tech_note: String,
@ -44,12 +45,26 @@ impl OsTicket {
}
}
pub fn add_error(&mut self, text: &str) {
let lines: Vec<&str> = text
.lines()
.filter(|line| {
let line = line.trim();
!line.is_empty() && !line.eq_ignore_ascii_case("ERROR")
})
.collect();
self.error = lines.join("\n");
}
pub fn disable(&mut self) {
self.connected = false;
self.disabled = true;
}
pub fn get_report(&self) -> String {
pub fn get_report(&mut self) -> String {
if !self.error.is_empty() {
self.report.push(format!("\n\nERROR: {}", self.error));
}
self.report.join("\n")
}

View file

@ -411,6 +411,9 @@ impl App {
Action::KeyUp => self.list.previous(),
Action::KeyDown => self.list.next(),
Action::Error(ref msg) => {
if let Ok(mut osticket) = self.osticket_arc.lock() {
osticket.add_error(msg);
}
self.action_tx
.send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?;
self.action_tx.send(Action::SetMode(Mode::Failed))?;
@ -473,61 +476,10 @@ impl App {
}
}
Mode::SelectDisks => {
if two.is_some()
&& let Ok(mut osticket) = self.osticket_arc.lock()
&& osticket.connected
&& !osticket.disabled
{
// Update osTicket report
info!("Updating OST Report (Before)...");
let disk_list = self.state.disk_list.lock().unwrap();
if let Some(source_index) = one
&& let Some(source_disk) = disk_list.get(source_index)
&& let Some(dest_index) = two
&& let Some(dest_disk) = disk_list.get(dest_index)
{
osticket.update_report(source_disk, ReportType::Source);
osticket.update_report(
dest_disk,
ReportType::Destination {
label: String::from("Before"),
},
);
}
}
// Update state
self.state.disk_index_source = one;
self.state.disk_index_dest = two;
}
Mode::SelectParts => {
if two.is_some()
&& let Ok(mut osticket) = self.osticket_arc.lock()
&& osticket.connected
&& !osticket.disabled
{
// Update osTicket report
info!("Updating OST Report (After)...");
let disk_list = self.state.disk_list.lock().unwrap();
if let Some(dest_index) = self.state.disk_index_dest
&& let Some(dest_disk) = disk_list.get(dest_index)
{
osticket.update_report(
dest_disk,
ReportType::Destination {
label: String::from("After"),
},
);
// Upload osTicket report
self.action_tx.send(Action::PostResponse {
color: ResponseColor::Normal,
text: osticket.get_report(),
})?;
}
}
// Update state
self.state.part_index_boot = one;
self.state.part_index_os = two;
}
@ -564,10 +516,15 @@ impl App {
_ => {}
}
self.set_mode(new_mode)?;
// Update components
self.action_tx
.send(Action::UpdateFooter(build_footer_string(self.cur_mode)))?;
self.action_tx.send(build_left_items(self))?;
self.action_tx.send(build_right_items(self))?;
// Update state
// TODO: Verify this shouldn't be before update components?
match new_mode {
Mode::SelectTableType | Mode::Confirm => {
// Select source/dest disks
@ -593,6 +550,65 @@ impl App {
}
_ => {}
};
// Update osTicket
match new_mode {
Mode::Confirm => {
if let Ok(mut osticket) = self.osticket_arc.lock()
&& osticket.connected
&& !osticket.disabled
{
info!("Updating OST Report (Before)...");
let disk_list = self.state.disk_list.lock().unwrap();
if let Some(source_index) = self.state.disk_index_source
&& let Some(source_disk) = disk_list.get(source_index)
&& let Some(dest_index) = self.state.disk_index_dest
&& let Some(dest_disk) = disk_list.get(dest_index)
{
osticket.update_report(source_disk, ReportType::Source);
osticket.update_report(
dest_disk,
ReportType::Destination {
label: String::from("Before"),
},
);
}
}
}
Mode::Done | Mode::Failed => {
if let Ok(mut osticket) = self.osticket_arc.lock()
&& osticket.connected
&& !osticket.disabled
{
info!("Updating OST Report (After)...");
let disk_list = self.state.disk_list.lock().unwrap();
if let Some(dest_index) = self.state.disk_index_dest
&& let Some(dest_disk) = disk_list.get(dest_index)
{
osticket.update_report(
dest_disk,
ReportType::Destination {
label: String::from("After"),
},
);
// Set color
let color = if new_mode == Mode::Failed {
ResponseColor::DiagFail
} else {
ResponseColor::Normal
};
// Upload osTicket report
self.action_tx.send(Action::PostResponse {
color,
text: osticket.get_report(),
})?;
}
}
}
_ => {}
}
}
Action::TasksComplete => self.action_tx.send(Action::NextScreen)?,
Action::UserNo => self.action_tx.send(Action::DismissPopup)?,
@ -912,6 +928,11 @@ fn build_right_items(app: &App) -> Action {
line_colors: vec![Color::Cyan],
}]);
}
start_index += 1;
items.push(vec![DVLine {
line_parts: vec![String::new()],
line_colors: vec![Color::Reset],
}]);
if let Some(index) = app.state.disk_index_dest {
start_index += 1;
let disk_list = app.state.disk_list.lock().unwrap();