Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Note: This code is intented for Caché 5.1 or higher.
- Task Definition:
- -------------------------
- /// Task to automate the collection of Buttons reports, and to automate them being sent to a recipient for archival and configuration history
- Class %SYS.Task.SendButtons Extends (%SYS.Task.Definition, %XML.Adaptor)
- {
- Parameter TaskName = "SendButtons";
- Parameter XMLNAME = "ProfilerData";
- /// if this field is filled, then the files are left in the local Archive
- Property ArchiveDirectory As %String(XMLPROJECTION = "NONE");
- /// flag to indicate if this should be a Big Buttons; default is to collect a "Small" Buttons
- Property BigButtons As %Boolean [ InitialExpression = 0 ];
- /// used to populate the "From:" field in the email generated to send the Buttons report
- Property EmailCC As %String(XMLPROJECTION = "NONE");
- /// used to populate the "From:" field in the email generated to send the Buttons report
- Property EmailFrom As %String(XMLPROJECTION = "NONE");
- /// used to populate the "Reply-To:" field in the email generated to send the Buttons report
- Property EmailReplyTo As %String(XMLPROJECTION = "NONE");
- /// name of SMTP server to use for sending %Buttons; if this is blank, the Buttons report will not be emailed
- Property SMTPServer As %String(XMLPROJECTION = "NONE");
- /// name of SMTP Authenticated User
- Property SMTPUser As %String(XMLPROJECTION = "NONE");
- /// password of SMTP Authenitcated User
- Property SMTPPass As %String(XMLPROJECTION = "NONE");
- /// SMTP port to use
- Property SMTPPort As %String(XMLPROJECTION = "NONE") [ InitialExpression = 25 ];
- /// flag to indicate if Butttons should be emailed to the Support when collected and not associated with a WRC issue#
- Property WRCHealthCheckEnabled As %Boolean(XMLPROJECTION = "NONE") [ InitialExpression = 0 ];
- /// WRC Issue Number to be included in subject; NOTE: This is cleared after a buttons is sent with this in the Subject line, and needs to be reinitilized through the System Management Portal
- Property WRCIssueNumber As %Integer(XMLPROJECTION = "NONE");
- /// if there are any Adhocs applies as changed files only, which didn't update the $ZV string, they should be listed here
- Property zInfoAdhocNotListedInZV As %String(XMLNAME = "AdhocNotListedInZV");
- /// manual field indicating the types of backups used on this instance of Caché
- Property zInfoBackupType As %String(XMLNAME = "BackupType");
- /// manual field indicating the type and quantity of CPU(s) used on this system
- Property zInfoCPUDetails As %String(XMLNAME = "CPUDetails");
- /// manual field indicating the type of hardware that this system is running on
- Property zInfoHardwareType As %String(MAXLEN = 500, XMLNAME = "HardwareType");
- /// manual property indicates what the primary use is for this Caché Instance: Development, Testing, QA or Production
- Property zInfoPrimaryPurpose As %String(DISPLAYLIST = ",Development,Testing,Quality Assurance,Production,", VALUELIST = ",Dev,Test,QA,Prod,", XMLNAME = "PrimaryPurpose");
- /// total physical memory on the machine
- Property zInfoTotalPhysicalMemory As %String(XMLNAME = "TotalPhysicalMemory");
- /// any special notes that the customer wants included with the %Buttons
- Property zzInfoNotesFromCustomer As %String(MAXLEN = 500, XMLNAME = "NotesFromCustomer");
- ClassMethod ArchiveDirectoryIsValid(ArchiveDirectory As %String) As %Status
- {
- If (ArchiveDirectory'="") {
- If '##class(%Library.File).DirectoryExists(ArchiveDirectory) Quit $$$ERROR($$$GeneralError,"Directory does not exist")
- }
- Quit $$$OK
- }
- /// This method is responsible for executing the task
- /// At the scheduled time, the Task Manager
- /// - creates an instance of this object,
- /// - Sets any property values using the stored "Settings" for the task,
- /// - and invokes this method to execute the task.
- Method OnTask() As %Status
- {
- If ..ArchiveDirectory'="" {
- Set Status = ##class(%SYS.Task.SendButtons).ArchiveDirectoryIsValid(..ArchiveDirectory)
- If 'Status Quit Status
- }
- If ..BigButtons {
- Set LogType = "Advanced"
- }
- Else {
- Set LogType = "Basic"
- }
- Set Status = $$INT^Buttons(LogType,..ArchiveDirectory)
- If $P(Status,"|",1) '= 1 Quit $$$ERROR($$$GeneralError,$P(Status,"|",2))
- Set FullFile = $P(Status,"|",2)
- // Buttons on VMS returns a trailing ";" in the filename which needs to be removed
- Set FullFile = $P(FullFile,";",1)
- // send if they have filled in the required information for Sending the report to the WRC
- If ..SMTPServer '= "",..EmailFrom '= "" {
- Set s=##class(%Net.SMTP).%New()
- Set AuthUser=$ZSTRIP(..SMTPUser,"<>W")
- Set objAuth=""
- If AuthUser]"" {
- #; use default authentication list
- set objAuth=##class(%Net.Authenticator).%New()
- Set objAuth.UserName=AuthUser
- Set objAuth.Password=..SMTPPass
- }
- If objAuth set s.authenticator=objAuth
- Set s.smtpserver=..SMTPServer
- Set s.port=..SMTPPort
- Set m = ##class(%Net.MailMessage).%New()
- Set m.From = ..EmailFrom
- Set m.ReplyTo = ..EmailReplyTo
- Set m.Subject = "Automated sending of "_FullFile
- If ..WRCIssueNumber '="" {
- Do m.To.Insert("support@foo.com")
- Set m.Subject = "Buttons for WRC"_..WRCIssueNumber
- }
- Do m.To.Insert("HealthCheck@foo.com")
- If ..EmailCC'="" {
- for i=1:1:$L(..EmailCC,",") {
- Do m.Cc.Insert($P(..EmailCC,",",i))
- }
- }
- Set m.Charset="iso-8859-1"
- Set Status = ..XMLExportToString(.body,,",indent")
- Set Status = m.TextData.Write(body)
- If $$$ISERR(Status) Quit $$$ERROR($$$GeneralError,Status)
- Set dir = ##class(%File).GetDirectory(FullFile)
- Set file = ##class(%File).GetFilename(FullFile)
- Set Status = m.AttachFile(dir,file,0,"iso-8859-1")
- If $$$ISERR(Status) Quit $$$ERROR($$$GeneralError,Status)
- Set Status = s.Send(m)
- If $$$ISERR(Status) Quit $$$ERROR($$$GeneralError,Status)
- }
- //if the customer hasn't defined an Archive Directory, but they are automatically creating reports on a schedule, then delete the file
- If ..ArchiveDirectory="",..WRCHealthCheckEnabled {
- Set Status = ##class(%File).Delete(FullFile)
- }
- //clear out the WRCIssue number so the customer will need to manually enter it again
- If ..WRCIssueNumber'="" {
- Set ..WRCIssueNumber = ""
- Set ..BigButtons = 0
- }
- Quit $$$OK
- }
- }
- -------------------------
- Initialization Routine (using %SYS.Task which inherits from %SYS.TaskSuper):
- ------------------------
- addbuttonstask
- write !,"This routine will initialize an automated Buttons task on this system.",!
- Write "This is intended for use with Cache 5.1 and greater",!,!
- Write "--- Adding a Task called 'Send Buttons' ---",!
- Write "This task can be used to email a Buttons report to Support.",!
- Write "If the Buttons is for an open ticket, prior to running this task, fill in",!
- Write "the WRCIssueNumber field in the task properties through the System",!
- Write "Management Portal.",!,!
- ///add task if not already found in schedule
- &sql(select Name from %SYS.Task where Name like 'Send Buttons')
- ///if not present add task
- if (SQLCODE'=0) {
- set Task=""
- Set Task=##Class(%SYS.Task).%New()
- Set Task.Name="Send Buttons"
- Set value=$$STRINGOPTION("Do you want to schedule Buttons to be collected on a regular basis","Y",1)
- If ($ZCONVERT(value,"L")="y")||($ZCONVERT(value,"L")="yes")||(value=$C(0)){
- Set Task.TimePeriod=0
- Set value=$$STRINGOPTION("Collect Buttons once every how many days","14",1)
- Set Task.TimePeriodEvery=value
- }
- else {
- Set Task.TimePeriod=5
- }
- Set Task.TimePeriodDay=""
- Set Task.Description="Send Buttons to Support On Demand, and/or on a schedule"
- Set Task.TaskClass="%ZSYS.Task.SendButtons"
- Set Task.RescheduleOnStart=1
- Set objTaskClass=$zobjclassmethod(Task.TaskClass,"%New")
- Do objTaskClass.SetSettings(Task.Settings)
- Set Settings=objTaskClass.GetSettings()
- For i=1:2:($ll(Settings)) {
- Set name=$li(Settings,i)
- Set value=$li(Settings,i+1)
- Set prompt=""
- If name="WRCHealthCheckEnabled" {
- Write !,!,"--- WRC Health Check ---",!
- Write "Your system can be configured to automatically send your periodically collected",!
- Write "Buttons reports to HealthCheck@foo.com.",!,!
- Set value=$$STRINGOPTION("Do you want to automatically send in Buttons reports","Y",1)
- If ($ZCONVERT(value,"L")="y")||($ZCONVERT(value,"L")="yes")||(value=$C(0)){
- Set $li(Settings,i,i+1)=$lb(name,1)
- }
- else {
- Set $li(Settings,i,i+1)=$lb(name,0)
- }
- continue
- }
- Elseif name="ArchiveDirectory" {
- Set prompt="If you want these Buttons archived, what directory should they be stored in"
- }
- ElseIf name="EmailCC" {
- Set prompt="Additional email addresses to CC: for outgoing emails (comma separated)"
- }
- ElseIf name="EmailFrom" {
- Set prompt="Address for the 'From:' field for outgoing emails"
- }
- ElseIf name="SMTPServer" {
- Set prompt="What SMTP Server should be used for outgoing emails"
- }
- ElseIf name="zInfoAdhocNotListedInZV" {
- Write !,!,"--- Additional Information for ISC Support ---",!
- Write "Answer these questions to give Support a better understanding of your system:"
- Set prompt="What (if any) Adhocs are applied that do not show up in $ZV"
- }
- ElseIf name="zInfoBackupType" {
- Set prompt="What kind of Backup is used on this system (Cache, External, OS, etc)"
- }
- ElseIf name="zInfoHardwareType" {
- Set prompt="What kind of hardware is Cache running on (as much detail as possible)"
- }
- ElseIf name="zInfoPrimaryPurpose" {
- Set prompt="What is the Primary Purpose of this Cache Instance (Dev/Test/QA/Prod)"
- }
- ElseIf name="zInfoTotalPhysicalMemory" {
- Set prompt="What is the total physical memory on this machine"
- }
- ElseIf name="zzInfoNotesFromCustomer" {
- Set prompt="What else would you like ISC Support to know about this Cache instance"
- }
- if prompt '="" {
- f {
- Set value=$$STRINGOPTION(prompt,value,1) q:value=$C(0)
- Set status=$zobjmethod(objTaskClass,name_"IsValid",value)
- Continue:'status
- Set $li(Settings,i,i+1)=$lb(name,value)
- Quit
- }
- }
- }
- Do objTaskClass.SetSettings(Settings)
- Set Settings=objTaskClass.GetSettings()
- Set Task.Settings=Settings
- Set Status=Task.%Save()
- if Status {
- write !,!,"Added Send Buttons task to schedule",!,!
- Set value=$$STRINGOPTION("Do you want to run a test Buttons report now","Y",1)
- If ($ZCONVERT(value,"L")="y")||($ZCONVERT(value,"L")="yes")||(value=$C(0)){
- set Status = ##class(%SYS.Task).RunNow(Task.%Id())
- if Status {
- Write !,"Task 'Send Buttons' was started successfully.",!
- Write "Please check the Task History in the SysMgtPtl to confirm that it completd.",!}
- else {Write !,"Failed to start 'Send Buttons' task",!}
- }
- Set Task=""
- }
- else { write !,!,"Failed to add Send Buttons task",! }
- } else {
- write !,!,"Task Send Buttons found already present",!
- }
- Quit
- quitRoutine
- w !,"Exiting Routine without creating Task",!
- q
- STRINGOPTION(prompt,default,allownull,same) [] {
- s $zt="STRINGOPTIONE"
- STRINGOPTION1 w !,prompt_"? " i default'="" w default_" => "
- s same=0
- r Option i Option="",(default'="") s same=1 q default
- i Option="",(allownull=0) w !,$get(^%qCacheMsg("%Utility",$select($isObject($get(%response)):%response.MatchLanguage(),1:$get(^%SYS("LANGUAGE","CURRENT"),"en")),"1380879397"),"Please enter a non-null value") g STRINGOPTION1
- q Option
- STRINGOPTIONE s $zt=""
- i $ze'["<INTERRUPT>" w !,$$FormatText^%occMessages($get(^%qCacheMsg("%Utility",$select($isObject($get(%response)):%response.MatchLanguage(),1:$get(^%SYS("LANGUAGE","CURRENT"),"en")),"1936651305"),"ERROR: %1"),$ZE)
- q $C(0)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement